akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N;
  cin>>N;
  int A[2][N];
  for(int i=0;i<N;i++)cin>>A[0][i];
  for(int i=0;i<N;i++)cin>>A[1][i];

  int answer=-1;
  for(int i =0;i<N;i++){
    int temp=0;
    for(int j=0;j<i+1;j++)temp+=A[0][j];
    for(int j=i;j<N;j++)temp+=A[1][j];
    if(answer<temp)answer=temp;
  }
  cout<<(answer);
  return 0;
}


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

int main(){
    int N,M,sum=0,count=0;
    cin >> N >> M;

    vector<int> vec(N);

    for(int i=0; i<N; i++){
        cin >> vec.at(i);
        sum+=vec.at(i);
    }

    for(int i=0; i<N; i++){
      if(sum <= 4*M*(vec.at(i))){
            count++;
        }
    }    
    if(M<=count){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main() {
    long X,K,D;
    long result = 0;
    cin >> X >> K >> D;
    if(X >= 0){
        if(X / D >= K){
            result = X - D * K;
        }
        else{
            if((K - X/D) % 2 == 1){
                result = X % D - D;
            }
            else{
                result = X % D;
            }
        }
    }
    else{
        X = -X;
        if(X / D >= K){
            result = X - D * K;
        }
        else{
            if((K - X/D) % 2 == 1){
                result = X % D - D;
            }
            else{
                result = X % D;
            }
        }
        result = -result;
    }

    cout << abs(result) <<"\n";
    return 0;
}

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

int main(){
  int n,l ;
  cin >> n >> l;
  vector<string> list(n);
  string ans ;
  for (int i=0; i<n; i++){
    cin >> list.at(i);
  }
  sort(list.begin(),list.end());
  for (int j=0; j<n; j++){
    ans += list.at(j);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 3352
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) < TMPend; (i)++)
#define RFOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) >= TMPend; (i)--)
#define REP(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int input(n);
  int list_input(a, n);
  long long dp[n + 1][n + 1][2];

  RFOR(l, n, 0) rep(r, n + 1) rep(taro, 2) {
    if (r - l <= 0) {
      dp[l][r][taro] = 0;
      continue;
    }

    long long R;
    if (taro) {
      R = max(
          dp[l + 1][r][!taro] + a[l],
          dp[l][r - 1][!taro] + a[r - 1]);
    } else {
      R = min(
          dp[l + 1][r][!taro] - a[l],
          dp[l][r - 1][!taro] - a[r - 1]);
    }
    dp[l][r][taro] = R;
  }
  out(dp[0][n][1]);
}


Measured memory_bytes: 140928
#include <stdio.h>

long long n, m;
long long cont = 0;

int main(){
    scanf("%d %d", &n, &m);
    long long esq = 0, lat = 0, cen=0;
    if(n >= 2 && m >= 2){
        cont=(m-2)*(n-2);
    } else {
        if(n > m) cont = n-2;
        else if(m > n) cont = m-2;
        else cont = 1;
    }

    /*
    if(n >= 2 && m >= 2) esq = 4;
    if(n >= 3){
        lat += n;
        if(esq > 0) lat -=2;
        if(m >= 3) lat *=2;
    }
    if(m >= 3){
        lat += m;
        if(esq > 0) lat -=2;
        if(n >= 3){
            lat += m;
            if(esq > 0) lat -= 2;
        }
    }
    cen = n*m -esq -lat;
    //printf("E:%d, L:%d, C:%d\n", esq, lat, cen);

    cont = cen;
    if(lat == m*n){esq = 2; cont += lat -2; }



    /*for(int i=0; i<n; i++){
        x=1;
        if(i > 0) x+=1;
        if(i < n-1) x+=1;
        int y = x;
        for(int j=0; j<m; j++){
            if(j > 0) x+=1;
            if(j > 0 && i > 0) x+=1;
            if(j > 0 && i < n-1) x+=1;
            if(j < m-1) x+=1;
            if(j < m-1 && i > 0) x+=1;
            if(j < m-1 && i < n-1) x+=1;
            //printf("%d,%d: %d\n", i,j, x);
            idx ++;
            if(x %2 != 0) cont +=1;
            x = y;
        }
    }*/
    printf("%lld\n", cont);
}


Measured memory_bytes: 128
A = gets.chomp.split(" ").map(&:to_i).map{|t| t-1}

B = []

(A[0]+1).times do
  v = gets.chomp.split("").map{|t| t=="#"}#.map(&:to_i)
  B << v 
end

cut=B.map{|t| t.select{|k| k}.size}.inject(:+)

def path_search(crt, his, pri)
  return his if crt == A
  his << crt
  if crt[0] == A[0]
    if B[crt[0]][crt[1]+1]
      path_search([crt[0], crt[1]+1], his, pri)
    else
      return nil
    end
  elsif crt[1] == A[1]
    if B[crt[0]+1][crt[1]]
      path_search([crt[0]+1, crt[1]], his, pri)
    else
      return nil
    end
  #p crt
  #p crt[0]
  #p A[0]-1
  else
  ans = [B[crt[0]+1][crt[1]],B[crt[0]][crt[1]+1]]
  if pri
    if ans[0]
      path_search([crt[0]+1, crt[1]], his, pri)
    elsif ans[1]
      path_search([crt[0], crt[1]+1], his, pri)
    else
      nil
    end
  else
    if ans[1]
      path_search([crt[0], crt[1]+1], his, pri)
    elsif ans[0]
      path_search([crt[0]+1, crt[1]], his, pri)
    else
      nil
    end
  end
  end
end

migi = path_search([0,0], [] , true)
shita = path_search([0,0], [], false)

if migi && shita && migi == shita && migi.size+1 == cut
  migi.each do |item|
    B[item[0]][item[1]]=false
  end
  puts "Possible"
else
  puts "Impossible"
end



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

using namespace std;

int N;
int A[100];

void solve() {
    int max = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) continue;
            if (abs(A[i] - A[j]) > max) max = abs(A[i] - A[j]);
        }
    }
    printf("%d\n", max);
    return;
}


int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    solve();
    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
    string Sd, T;
    vector<string> Sv;
    cin >> Sd >> T;
    for(int i = 0; i + T.length() <= Sd.length(); i++){
        string Sdc = Sd;
        for(int j = 0; j < T.length(); j++){
            if(Sdc[i + j] != '?' && Sdc[i + j] != T[j]) goto next;
        }
        for(int j = 0; j < T.length(); j++){
            Sdc[i + j] = T[j];
        }
        replace(Sdc.begin(), Sdc.end(), '?', 'a');
        Sv.push_back(Sdc);
        next:;
    }
    sort(Sv.begin(), Sv.end());
    if(Sv.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << Sv[0] << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline
MOD = 1000000007

X = int(input())

sa = 100000
res = 0

if X == 1:
    print(1)
else:
    for i in range(2,X):
        a = int(math.log(X,i)+0.00000004)
        if (sa > (X - (i**a))) & ( a != 1):
            sa = X - (i**a)
            res = i**a

    print(res)


Measured memory_bytes: 3316
const_num = 1000000007

N, K = gets.chomp.split(' ').map(&:to_i)
nums = gets.chomp.split(' ').map(&:to_i)

counts = Array.new(N)
N.times do |i|
  target = nums[i]
  counts[i] = [0, 0]
  N.times do |j|
    next if i == j
    compare = nums[j]
    next if target <= compare
    if i < j
      counts[i][1] += 1
    else
      counts[i][0] += 1
    end
  end
end

answer = 0
N.times do |i|
  num1 = counts[i][0]
  num2 = counts[i][1]
  answer = (answer + (K * K * num2 + K * (K - 1) * num1 - (num1 + num2) * (K * (K + 1) / 2 - K))) % const_num;
end

p answer


Measured memory_bytes: 2172
N = int(input())
vH = list(map(int, input().split()))

INF = float("inf")

vH = [INF,] + vH
dp = [INF, 0,]
for i in range(2, N+1):
    dp.append(min(dp[-1] + abs(vH[i] - vH[i-1]),
                  dp[-2] + abs(vH[i] - vH[i-2])))

print(dp[-1])


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

int solve(vector<int> &dp, vector<vector<int>> &edges, int now)
{
	if (0 <= dp[now])
	{
		return dp[now];
	}
	bool f = true;
	for (int next : edges[now])
	{
		dp[now] = max(dp[now], solve(dp, edges, next) + 1);
		f = false;
	}
	if (f)
	{
		return dp[now] = 0;
	}
	return dp[now];
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> edges(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		edges[a].emplace_back(b);
	}
	vector<int> dp(n, -1);
	for (int i = 0; i < n; i++)
	{
		solve(dp, edges, i);
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}

Measured memory_bytes: 8832
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String C = sc.next();
        char c[] = C.toCharArray();
        String eng = "abcdefghijklmnopqrstuvwxyz";
        
        for(int i = 0; i < 25; i++){
            if(c[0] == eng.charAt(i)){
                c[0] = eng.charAt(i+1);
                break;
            }
        }

        // 出力
        System.out.println(c[0]);
    }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 mod2comb(int32 n, int32 r){
  return n == (r | (n - r));
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> a(n);
  bool oneExit = false;
  REP(i,n){
    char c;
    cin >> c;
    a[i] = c - '1';
    if(a[i] == 1)oneExit = true;
  }
  int32 sum = 0;
  REP(i,n){
    sum += a[i] * mod2comb(n-1, i);
    sum %= 2;
  }
  if(sum == 1){
    ANS(1);
    return 0;
  }
  if(oneExit){
    ANS(0);
    return 0;
  }
  sum = 0;
  REP(i,n){
    sum += a[i] / 2 * mod2comb(n-1, i);
    sum %= 2;
  }
  ANS(sum * 2);
  return 0;
}

Measured memory_bytes: 8064
package main

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

func solve() {
	w, h := getFloat(), getFloat()
	x, y := getFloat(), getFloat()

	// 2つに分割されたうち小さい方の面積の最大値
	fmt.Fprintln(wr, w*h/2)

	// 上記の最大値を達成する方法が複数あるかどうか
	if (w/2 == x) && (h/2 == y) {
		fmt.Fprintln(wr, 1)
	} else {
		fmt.Fprintln(wr, 0)
	}
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

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

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}

func getFloat() float64 {
	f, err := strconv.ParseFloat(getString(), 64)
	if err != nil {
		panic(err)
	}
	return f
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		while (sc.hasNext()) {
			int n = sc.nextInt();

			int ans = n*(n+1)/2 + 1;

			System.out.println(ans);
		}

	}

}

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

int main() {
  long int n,s,left,right;
  cin>>n;
  vector<long int> a(n+2);
  a.at(0)=0;
  a.at(n+1)=0;
  s=0;
  for(long int i=1;i<n+1;i++){
    cin>>a.at(i);
    s+=abs(a.at(i)-a.at(i-1));
  }
  s+=abs(a.at(n+1)-a.at(n));
  for(long int i=1;i<n+1;i++){
    long int ans=s;
    left=min(a.at(i-1),a.at(i+1));
    right=max(a.at(i-1),a.at(i+1));
    if(a.at(i)<left)
      ans-=2*abs(left-a.at(i));
    else if(a.at(i)>right)
      ans-=2*abs(right-a.at(i));
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n,m; cin >> n >> m;
    vector<int> ans(m,0);
    rep(i,n){
        int k; cin >> k;
        rep(j,k){
            int a; cin >> a;
            ans[a-1]++;
        }
    }
    int ANS=0;
    rep(i,m){
        if(ans[i]>=n) ANS++;
    }
    cout << ANS << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxn 55
#define limit 2500
using namespace std;
struct edge {
	int v,a,b;
};
vector<edge> G[maxn];
int value[maxn],cost[maxn];
struct state {
	int u,num;
	ll tim;
	bool operator < (const state& a) const{
		return tim > a.tim;
	}
};
ll dis[maxn][maxn*maxn];
void dijkstra(int s) {
	s = min(s,limit);
	
	memset(dis,-1,sizeof dis);
	dis[1][s] = 0;
	priority_queue<state> pq;
	pq.push(state{1,s,0});
	
	while(!pq.empty()) {
		state now = pq.top();
		pq.pop();
		
		int u = now.u , num = now.num;
		ll tim = now.tim;
		if(dis[u][num] != tim)	continue;
		
		for(edge e : G[u]) {
			int v = e.v , a = e.a , b = e.b;
			if(num >= a) {
				if(dis[v][num - a] == -1 || dis[v][num - a] > tim + b) {
					dis[v][num - a] = tim + b;
					pq.push(state{v,num - a,tim + b});
				}
			}
		}
		
		num += value[u] , tim += cost[u];
		if(num <= limit && (dis[u][num] == -1 || dis[u][num] > tim)) {
			dis[u][num] = tim;
			pq.push(state{u,num,tim});
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,s;
	cin >> n >> m >> s;
	while(m--) {
		int u,v,a,b;
		cin >> u >> v >> a >> b;
		G[u].push_back(edge{v,a,b});
		G[v].push_back(edge{u,a,b});
	}
	for(int i=1;i<=n;i++)
		cin >> value[i] >> cost[i];
	
	dijkstra(s);
	
	for(int i=2;i<=n;i++) {
		ll ans = -1;
		for(int j=0;j<=limit;j++)
			if(dis[i][j] != -1 && (ans == -1 || ans > dis[i][j]))
				ans = dis[i][j];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6460
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    if(s.size() > 1 && s[0] == s[1]) {
        cout<<1<<' '<<2<<endl;
        return 0;
    }
    for(int i = 0; i+2 < s.size(); ++i) {
        set<char> st;
        st.insert(s[i]);
        st.insert(s[i+1]);
        st.insert(s[i+2]);
        if(st.size() < 3) {
            cout<<i+1<<' '<<i+3<<endl;
            return 0;
        }

    }
    cout<<-1<<' '<<-1<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	int sum=0;
	cin >> a >> b;
	for(int i=1;i<=b;i++){
		int t;
		cin >> t;
		sum+=t;
	}
	if(sum>=a)
	cout << "Yes" << endl;
	else
	cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int MM = 2e5 + 4;
ll mat[16][16];
ll dp[1 << 16], val[1 << 16];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> mat[i][j];
		}
	}
	for(int i = 0; i < (1 << n); i++) {
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < j; k++) {
				if(i & (1 << j)) {
					if(i & (1 << k)) {
						val[i] += mat[j][k];
					}
				}
			}
		}
	}
	for(int m = 0; m < (1 << n); m++) {
		for(int sm = m; sm > 0; sm = m & (sm - 1)) {
			dp[m] = max(dp[m], dp[m ^ sm] + val[sm]);
		}
	}
	cout << dp[(1 << n) - 1];
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var s = Console.ReadLine() + "Z";
        var cnt = 0;
        var ans = 0;
        var ATCG = "ATCG";
        for(var i = 0;i < s.Length;i++){
            if(ATCG.Contains(s[i])){
                cnt++;
            }else{
                ans = Math.Max(ans,cnt);
                cnt = 0;
            }
        }
        Console.WriteLine(ans);
    }
}


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

using namespace std;

string s;

void solve(){
    cin>>s;
    s += '1';
    char prev = '0';
    int cnt = 0, ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == prev)    cnt++;
        else {
            if(prev == 'R')
                ans = max(ans, cnt);
            cnt = 1;
            prev = s[i];
        }
    }
    cout<<ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TC;
    //cin>>TC;
    TC=1;
    while(TC--){
        solve();
    }
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String line=sc.nextLine();
		
		if(line.equals("RRR")) {
			System.out.println(3);
		}else if(line.equals("SSS")) {
			System.out.println(0);
		}else if(line.equals("RRS") ||line.equals("SRR")){
			System.out.println(2);
		}else {
			System.out.println(1);
		}	

	}

}


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

int q, i, ans, n, p, r, b;
bool f;
int main(){
        cin >> q;
        for (i = 0; i < q; i++){
                f = 1;
                ans = 0;
                map<int, int> mp;
                cin >> n;
                mp[n]++;
                while(1){
                        if (n < 10) break;
                        int j = 10;
                        b = 0;
                        while (n / j > 0){
                                p = n / j;
                                r = n % j;
                                b = max(b, p * r);
                                j *= 10;
                        }
                        n = b;
                        //cout << n << endl;
                        if (mp[n] > 0){
                                f = 0;
                                break;
                        }
                        mp[n]++;
                        ans++;
                }
                cout << (f ? ans : -1) << endl;
        }
        return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

const int inf = 1000000;

const int N = (int)2e5 + 7;
int n, a[N], p[N];
ll k;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        p[i] = -1;
    }

    int i = 1, cur = 0;
    while (p[i] == -1) {
        p[i] = cur;
        cur++;
        i = a[i];
    }
    if (k < cur) {
        for (int i = 1; i <= n; i++) {
            if (p[i] == k) {
                cout << i << endl;
            }
        }
    } else {
        k -= p[i];
        k %= (cur - p[i]);
        k += p[i];
        for (int i = 1; i <= n; i++) {
            if (p[i] == k) {
                cout << i << endl;
            }
        }
    }
}




Measured memory_bytes: 5188
#!/usr/bin/env python3
import itertools
import math

N = int(input().split()[0])
xy_list = []

for _ in range(N):
    x, y = list(map(int, input().split()))
    xy_list.append((x, y))

l = list(range(N))
p_list = list(itertools.permutations(l))
m_list = []
total = 0
count = 0
for p in p_list:
    count += 1
    t = 0
    for i, a in enumerate(p[:-1]):
        ax, ay = xy_list[a]
        bx, by = xy_list[p[i + 1]]
        t += ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
    total += t

ans = total / count

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
	cin >> s;
	bool f;
	while(s.size() > 3){
		f = true;
		string t = "";
		char c = 'B';
		if(s.substr(0,3) == "ABC")c = 'A';
		else if(s.substr(s.size()-3,3) == "ABC")c = 'C';
		rep(i,s.size()){
			if(s.substr(i,3) == "ABC"){
				i += 2;
				t += c;
			}
			else{
				t += s[i];
				if(s[i] == c)f = false;
			} 
		}
		if(!f || s.size() == t.size())break;
		s = t;
	}
	if(s == "ABC")cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3240
import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a - 1 for a in A]

log_K = 1
while 1 << log_K < K:
    log_K += 1
# print(f'{log_K=}')
D = [[0] * N for _ in range(log_K)]
for i in range(N):
    D[0][i] = A[i]
for k in range(log_K - 1):
    for i in range(N):
        D[k + 1][i] = D[k][D[k][i]]
# print(f'{D=}')

now = 0
k = 0
while K > 0:
    if K & 1:
        now = D[k][now]
    K = K >> 1
    k += 1
print(now + 1)


Measured memory_bytes: 197172
#include<iostream>
#include<cstdio>
int a,b,c,x,ans=0;
int main() {
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i=0;i<=a;i++) for(int j=0;j<=b;j++) for(int k=0;k<=c;k++) ans+=(i*500+j*100+k*50==x);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int dx[4]={1,-1,0,0};
  int dy[4]={0,0,1,-1};
  int H,W;
  cin>>H>>W;
  vector<string>S(H);
  ll ans=0;
  for(int i=0;i<H;i++)cin>>S[i];
  for(int sx=0;sx<W;sx++){
    for(int sy=0;sy<H;sy++){
      if(S[sy][sx]=='#')continue;
      vector<vector<ll>>cost(H,vector<ll>(W,0));
      vector<vector<bool>>used(H,vector<bool>(W,false));
      queue<pair<pii,ll>>q;
      q.push({{sx,sy},0});
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(S[i][j]=='#')used[i][j]=true;
        }
      }
      used[sy][sx]=true;
      while(q.size()>0){
        int x=q.front().first.first;
        int y=q.front().first.second;
        ll c=q.front().second;
        cost[y][x]=c;
        q.pop();
        for(int i=0;i<4;i++){
          int X=x+dx[i];
          int Y=y+dy[i];
          if(0<=X&&X<W&&0<=Y&&Y<H&&S[Y][X]=='.'&&used[Y][X]==false){
            q.push({{X,Y},c+1});
            used[Y][X]=true;
          }
        }
      }
      for(auto it:cost)for(auto it2:it)ans=max(ans,it2);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

const int inf = 1000000000000000LL;

signed main() {
	int n, m;
	cin >> n >> m;
	vector<int> d(m, n);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, k) {
			int a;
			cin >> a;
			d[a - 1]--;
		}
	}
	int ans = 0;
	rep(i, m) {
		if(d[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
connect_matrix = [ list(input()) for i in range(n) ]

def bfs(x):
    node_set = [ None for i in range(n)]
    color_list = [ "White" for i in range(n) ]
    search_list = [x]
    d = 0
    node_set[x] = 0
    color_list[x] = "Black"
    ans = 0
    while search_list != []:
        d += 1
        new_search_list = []
        for i in search_list:
            for j, v in enumerate(connect_matrix[i]):
                if v == "1":
                    if color_list[j] == "White":
                        if node_set[j] is None:
                            node_set[j] = node_set[i] + 1

                        new_search_list.append(j)
                        color_list[j] = "Black"
                    else:
                        if (node_set[j] + node_set[i]) % 2 == 0:
                            ans = -1
        search_list = new_search_list
    return ans, d-1

judge_list = []
dist_list = []
for i in range(n):
    a = bfs(i)
    judge_list.append(a[0])
    dist_list.append(a[1])

if -1 in judge_list:
    print(-1)
else:
    print(max(dist_list)+1)

Measured memory_bytes: 44780
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# [a, b].min が遅いので
def min(a, b)
  return a < b ? a : b
end

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end
N, p_list = gets_n_and_i_list

count = 0
min = N + 1
p_list.each do |p|
  if p < min
    count += 1
    min = min(p, min)
  end
end

puts count

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

using namespace std;
using ll = long long;

int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n);
    for(auto& it : x) cin >> it;
    vector<ll> y(m);
    for(auto& it : y) cin >> it;

    ll X=0;
    for(int i=0;i<n;i++) {
        X += (n-2*i-1)*x[i];
        X %= 1000000007;
    }
    
    ll Y=0;
    for(int i=0;i<m;i++) {
        Y += (m-2*i-1)*y[i];
        Y %= 1000000007;
    }
    

    cout << X*Y%1000000007 << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int a=1,j,i=0,n[10000];
    while(a != 0)
    {
        scanf("%d",&a);
        n[i] = a;
        ++i;
        j = i;
    }
    while(i > 1)
    {
    	printf("Case %d: %d\n",j+1-i,n[j-i]);
    	--i;
    }
}


Measured memory_bytes: 2732
#include <stdio.h>
int main(){
  int W, H, x, y, r;
  scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
  if(0+r <= x && x <= W-r && 0+r <= y && y <= H-r){
   printf("Yes\n");
 } else {
   printf("No\n");
 }
  return 0;
}




Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	char s;
	cin >> s;
	if (isupper(s))
		cout << "A" << endl;
	else
	{
		cout << "a" << endl;
	}
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		vi in(n);
		rep(i,n)cin>>in[i];
		sort(all(in));
		int t=in[n/2];
		bool h=false;
		rep(i,(n+1)/2)if(in[i]==t&&t==in[i+n/2]){
			h=true;
			cout<<t<<endl;
			break;
		}
		if(!h)cout<<"NO COLOR"<<endl;
	}
}

Measured memory_bytes: 11908
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    ++n;
    string s = to_string(n);
    int N = s.length();

    int M = 1 << 3;
    vector<vector<int>> dp(2, vector<int>(M, 0));
    dp[0][0] = 1;
    auto ndp = dp;
    for (int _ = 0; _ < N; ++_) {
        int d = s[_] - '0';
        for (auto& V : ndp) {
            fill(V.begin(), V.end(), 0);
        }
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < M; ++j) {
                if (dp[i][j] == 0) {
                    continue;
                }

                int r = 9;
                if (i == 0) {
                    r = d;
                }
                for (auto x : {3, 5, 7}) {
                    if (x > r) {
                        continue;
                    }

                    int ni = i;
                    int nj = j;
                    if (x < d) {
                        ni = 1;
                    }
                    nj |= 1 << ((x - 3) / 2);

                    ndp[ni][nj] += dp[i][j];
                }
            }
        }
        swap(ndp, dp);
        dp[1][0] += 1;
    }

    cout << dp[1][M - 1] << '\n';
    
    return 0;
}

Measured memory_bytes: 256
//PDF解説分かりにくかったがおそらくこういうこと？
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  int64_t k;
  cin>> n >> k;
  vector<int> a(n),f(n);
  for (int i=0; i<n; i++) cin>> a[i];
  for (int i=0; i<n; i++) cin>> f[i];
  sort(a.begin(),a.end()); sort(f.begin(),f.end()); reverse(f.begin(),f.end());
  
  int64_t l=0,r=1e12,num,tk,ans;
  map<int64_t,bool> m; m[-1]=false; m[1e12]=true; //番兵を忘れずに
  while (true){
    tk=k;
    num=(l+r)/2;
    for (int i=0; i<n; i++){
      tk-=max((int64_t)0,a[i]-num/f[i]);
    }
    if (tk<0){
      m[num]=false; l=num;
      if (m.count(num+1) && m[num+1]){ ans=num+1; break;}
    }
    else{
      m[num]=true; r=num;
      if (m.count(num-1) && !m[num-1]){ ans=num; break;}
    }
  }
  cout<< ans << endl;
}

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

import math

A, B = map(int, input().split())

if A == B:
    print(A)
else:
    ans = ((B - A + 2) % 4) // 2 if A % 2 == 1 else ((B - A + 1) % 4) // 2
    for i in range(1, int(math.log(B, 2)) + 1):
        D, Dp1 = 2 ** i, 2 ** (i + 1)
        a, b = A % Dp1, B % Dp1
        ad, bd = a // D, b // D

        if a == b:
            ans += D * ad
        elif ad == 0 and bd == 0:
            ans += 0
        elif ad == 0 and bd == 1:
            ans += D * ((b + 1) % 2)
        elif ad == 1 and bd == 0:
            ans += D * (a % 2)
        elif ad == 1 and bd == 1:
            ans += D * ((a - b + 1) % 2)

    print(ans)


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

typedef long long ll;
typedef vector<vector<ll>> matrix;
int N;
ll K;
const ll MOD = 1e9 + 7;

matrix ip_mod_matrix(matrix a, matrix b)
{
    matrix res(N);
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++)
    {
        ll aij = 0;
        for(int k = 0; k < N; k++) aij += a[i][k] * b[k][j] % MOD;
        aij %= MOD;
        res[i].push_back(aij);
    }
    return res;
}

matrix id_matrix()
{   
    vector<ll> row(N, 0);
    matrix res(N, row);
    for(int i = 0; i < N; i++) res[i][i] = 1;
    return res;
}

matrix pow_mod_matrix(matrix a, ll n)
{
    matrix res = id_matrix();
    ll tmp = n;
    matrix powmtx = a;
    while(tmp > 0)
    {
        if(tmp & 1) res = ip_mod_matrix(res, powmtx);
        tmp >>= 1;
        powmtx = ip_mod_matrix(powmtx, powmtx);
    }
    return res;
}

ll sum_elem_matrix(matrix a)
{
    ll res = 0;
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++) res += a[i][j] % MOD;
    return res %= MOD;
}

int main()
{
    cin >> N >> K;
    matrix a(N);
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++)
    {
        int t;
        cin >> t;
        a[i].push_back(t);
    }

    cout << sum_elem_matrix(pow_mod_matrix(a, K)) << endl;

}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 2e5 + 7;
int ar[N];
int main()
{
	fastio;

	int n;
	cin >> n;

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

	ll res = 0;
	for (int i = 1; i < n; ++i)
	{
		if (ar[i] >= ar[i-1]) continue;

		res += (ar[i-1] - ar[i]);
		ar[i] = ar[i-1];
	}
	cout << res << '\n';

	return 0;
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (s); i <= (t); ++i)
#define repD(i,t,s) for(int i = (t); i >= (s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1) / (d) + 1)
#define parity(a,b) (((a)^(b)) & 1 ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = (1 << 30) - 1;
const ll INF_64 = (1LL << 62) - 1;
const int MOD = 1e9 + 7;

ull nxt_sbset(ull s){
	ull tmp = s + (s & -s);
	ull btm = (~tmp & s) / (s & -s) >> 1;
	return btm | tmp;
}

int n,k,a[5000];

bool judge(int idx){
	bitset<5001> bts;
	bts.set(0);
	int i = 0;
	while(i < n && a[i] < k) if(idx != i) bts |= bts << a[i++]; else ++i;
	repU(j,max(0,k - a[idx]),k - 1) if(bts[j]) return 0;
	return 1;
} 

int srch(){
	int l = 0,u = n;
	while(u - l > 1){
		int m = (u + l) / 2;
		if(judge(m)) l = m;
		else u = m;
	}
	if(l) return l;
	return judge(0) - 1;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n >> k;
	rep(i,n) cin >> a[i];
	sort(a,a + n);
	cout << 1 + srch() << endl;
}





Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int x,n,a[110];
bool vis[110];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>x>>n;
	for(int i=1;i<=n;i++) cin>>a[i],vis[a[i]]=1;
	int t=-1,ans=-1;
	for(int i=0;i<=101;i++) if(!vis[i]){
		if(t==-1||abs(x-i)<t){
			t=abs(x-i);
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 100001;
const int maxk = 17;
struct info{
	int v, c, w;
};
struct query{
	int id, c, w, y;
};
int n, sz[maxn], g[maxn], top[maxn], up[maxn], depth[maxn], m;
long long ans[maxn];
vector < info > edge[maxn];
vector < query > ask[maxn];
int get_lca(int a, int b){
	while(g[a] != g[b])
		if(depth[top[g[a]]] < depth[top[g[b]]])b = up[top[g[b]]];
		else a = up[top[g[a]]];
	return depth[a] < depth[b] ? a : b;
}
void dfs1(int now, int last = 1){
	static int now_d = 0;
	up[now] = last;
	depth[now] = now_d++;
	sz[now] = 1;
	if(last != now){
		for(int i = 0;i < edge[now].size();++i)
			if(edge[now][i].v == last){
				edge[now].erase(edge[now].begin() + i);
				break;
			}
	}
	for(int i = 0;i < edge[now].size();++i){
		dfs1(edge[now][i].v, now), sz[now] += sz[edge[now][i].v];
		if(sz[edge[now][i].v] > sz[edge[now][0].v])swap(edge[now][i], edge[now][0]);
	}
	--now_d;
}
void dfs3(int now){
	static int now_g = 0;
	g[now] = now_g;
	if(!top[now_g])top[now_g] = now;
	if(!edge[now].empty()){
		dfs3(edge[now][0].v);
		for(int i = 1;i < edge[now].size();++i)
			++now_g, dfs3(edge[now][i].v);
	}
}
void dfs2(int now, int last = 1){
	static int total_w = 0;
	static int q_of[maxn] = {};
	static int w_of[maxn] = {};
	for(auto &i : ask[now]){
		ans[i.id] += (total_w - w_of[i.c] + q_of[i.c] * i.y) * i.w;
	}
	for(auto &i : edge[now]){
		if(i.v != last){
			++q_of[i.c];
			w_of[i.c] += i.w;
			total_w += i.w;
			dfs2(i.v, now);
			--q_of[i.c];
			w_of[i.c] -= i.w;
			total_w -= i.w;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs1(1);
	dfs3(1);
	for(int i = 0, x, y, u, v;i < m;++i){
        cin >> x >> y >> u >> v;
		ask[u].push_back({i, x, 1, y});
		ask[v].push_back({i, x, 1, y});
		ask[get_lca(u, v)].push_back({i, x, -2, y});
	}
	dfs2(1);
	for(int i = 0;i < m;++i)cout << ans[i] << '\n';
}


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

int main() {
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	rep(i, m) cin >> b[i];
	vector<vector<int>> a(n, vector<int>(m));
	rep(i, n) {
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	rep(i, n) {
		int sum = 0;
		rep(j, m) {
			sum += a[i][j] * b[j];
		}
		if (sum + c > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f;
int main()
{
    map <string,int> mp;
    int n;
    cin>>n;
    string s;
    for(int i=1;i<=n;i++){
        cin>>s;
        if(mp.find(s)==mp.end()) mp[s]=1;
        else mp[s]++;
    }
    cout<<mp.size();
    return 0;

}


Measured memory_bytes: 19220
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define FORR(x,arr) for(auto& x:arr)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
// clang-format on
using namespace std;
typedef signed long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  std::random_device rd;
  std::mt19937 ran(rd());

  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < (int)s.length(); ++i) {
    if (s[i] != 'A' and s[i] != 'T' and s[i] != 'C' and s[i] != 'G') {

      cnt = 0;
    } else {
      cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}


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

const int mod = pow(10, 9) + 7;

int main() {
  long long int n;
  cin >> n;
  vector<long long int> A(n);
  long long int total = 0;
  for(int i=0;i<n;i++) {
    cin >> A[i];
    total += (A[i] % mod);
    total %= mod;
  }

  long long int minus = 0;

  for(int k=0; k<60;k++) {
    long long int l = 0;
    for(int i=0;i<n;i++) {
      bitset<60> B(A[i]);
      if(B.test(k)) l++;
    }
    
    minus += (((long long int)pow(2, k+1) % mod) * ((l * (l-1) / 2) % mod)) % mod;
    minus %= mod;
  }

  int ans = ((total * (n-1)) % mod - minus) % mod;

  if(ans < 0) cout << ans + mod << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

const int MAXN = 1000000;
Int fact[MAXN], inv[MAXN];

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for(int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

Int comb(int n, int r) {
    if(r < 0 || n < r) return 0;
    return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

Int cnt[50];

Int calc(Int N, Int k){
    Int ret = 0;
    ret += ((N+1)/(1LL << (k+1)))*(1LL<<k);
    ret += max((N+1)%(1LL << (k+1))-(1LL<<k), 0LL);
    return ret;
}

vector<pair<Int, Int>> ab;

int main(){
    cin.tie(0);

    Int N, M; cin >> N >> M;
    for (int i = 0; i < N; i++){
        Int A, B; cin >> A >> B;
        ab.push_back({A, B});
    }
    sort(ab.begin(), ab.end());
    Int ans = 0;
    for (int i = 0; i < N; i++){
        ans += ab[i].first * min(M, ab[i].second);
        M -= min(M, ab[i].second);
        if (!M) break;
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 2420
import sys
import math
input = sys.stdin.readline

a, b, x = (int(i) for i in input().split())
#a = [int(i) for i in input().split()]
#print(a*a*b-x)
if x < a*a*b - a*a*b/2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    print(math.degrees(math.atan(2*(a*a*b-x)/(a*a*a))))


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

int judge(string s){
	int n = s.size();
	int c_count = 0;
	for (int i = 0; i < n; i++){
		if (i == 0){
			if (s[i] != 'A') return 0;
		}
		else if (i >= 2 and i < n-1 and s[i]=='C') c_count++;
		else{
			if ('a' <= s[i] and s[i] <= 'z'){
			}else{
				return 0;
			}
		}
	}
	if (c_count == 1) return 1;
	else return 0;
}

//0123456789
//  C     C

int main(){
	string s;
	cin >> s;
	if (judge(s) == 1) cout << "AC\n";
	else cout << "WA\n";

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

void solve() {
    string s;
    cin >> s;
    int N = count(s.begin(), s.end(), 'N');
    int W = count(s.begin(), s.end(), 'W');
    int S = count(s.begin(), s.end(), 'S');
    int E = count(s.begin(), s.end(), 'E');
    if (N*S == 0 && N+S != 0) {
        cout << "No" << endl;
        return;
    }
    if (W*E == 0 && W+E != 0) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
}

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


Measured memory_bytes: 256
/**
 * 
 */
import java.util.*;
/**
 * @author akira
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int[] card = new int[5];
			String str = scan.next();
			for(int i = 0;i < 4;i++){
				card[i] = Integer.parseInt(str.substring(0,str.indexOf(",")));
				str = str.substring(str.indexOf(",") + 1,str.length());
			}
			card[4] = Integer.parseInt(str);
			System.out.println(Poker.yaku(card));
		}
	}
	


}

class Poker {
	static String yaku(int[] card) { // cardに格納するのは1~13の数字のみとする
		int[] cardNum = new int[13];
		for (int i = 0; i < 5; i++) {
			cardNum[card[i] - 1]++; // ここで -1 とするのは要素番号に沿わせるため
		}
		if (jFourcard(cardNum)) {
			return "four card";
		}
		else if (jFullhouse(cardNum)) {
			return "full house";
		}
		else if (jStraight(cardNum)) {
			return "straight";
		}
		else if (jThreecard(cardNum)) {
			return "three card";
		}
		else if (jTwopair(cardNum)) {
			return "two pair";
		}
		else if (jOnepair(cardNum)) {
			return "one pair";
		}
		return "null";

	}

	static boolean jFourcard(int[] cardNum) {
		for (int i = 0; i < 13; i++) {
			if (cardNum[i] == 4) {
				return true;
			}
		}
		return false;
	}

	static boolean jFullhouse(int[] cardNum) {
		boolean b1 = false, b2 = false;
		for (int i = 0; i < 13; i++) {
			if (cardNum[i] == 2) {
				b1 = true;
			} else if (cardNum[i] == 3) {
				b2 = true;
			}
		}
		return b1 && b2;
	}

	static boolean jStraight(int[] cardNum) {
		for (int i = 0; i < 9; i++) {
			if (cardNum[i] == 1 && cardNum[i + 1] == 1 && cardNum[i + 2] == 1
					&& cardNum[i + 3] == 1 && cardNum[i + 4] == 1) {
				return true;
			}
		}
		if (cardNum[9] == 1 && cardNum[10] == 1 && cardNum[11] == 1
				&& cardNum[12] == 1 && cardNum[0] == 1) {
			return true;
		}
		return false;
	}

	static boolean jThreecard(int[] cardNum) { // これはフルハウスを使用後に使用するべきメソッド
		for (int i = 0; i < 13; i++) {
			if (cardNum[i] == 3) {
				return true;
			}
		}
		return false;
	}

	static boolean jTwopair(int[] cardNum) {
		int cnt = 0;
		for (int i = 0; i < 13; i++) {
			if (cardNum[i] == 2) {
				cnt++;
			}
		}
		return cnt == 2;
	}

	static boolean jOnepair(int[] cardNum) {
		for (int i = 0; i < 13; i++) {
			if (cardNum[i] == 2) {
				return true;
			}
		}
		return false;
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve()
{
  int n, a, ans;
  cin >> n >> ans;
  for(int i = 1; i < n; ++i)
  {
    cin >> a;
    ans = gcd(a, ans);
  }

  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3612
// Ants on a Circle
// * frank_c1
// * 2017 / 11 / 17

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int maxn = (int)(1e5) + 5;
int a[maxn], w[maxn];
pii b[maxn];

int main() {
	int n, L, T;
	scanf("%d%d%d", &n, &L, &T);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a[i], &w[i]);
		b[i] = make_pair((int)((a[i] + (w[i] == 1 ? 1LL : L - 1LL) * T) % L), w[i]);
	} pii now = b[0]; 
	sort(b, b + n); T = T * 2 - 1; LL cnt = 0, s = w[0] == 1 ? 1LL : n - 1LL;
	for (int i = 1; i < n; ++i) if (w[0] != w[i]) {
		int dt = w[i] == 2 ? (a[i] + L - a[0]) % L : (a[0] + L - a[i]) % L;
		if (dt <= T) (cnt += s * (1 + (T - dt) / L)) %= n;
	}
	int p = 0; while (now != b[p]) ++p; (p += n - cnt) %= n;
	for (int i = 0; i < n; ++i) printf("%d\n", b[p].first), (p += 1) %= n;
	return 0;
}

Measured memory_bytes: 2816