akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
const int MX = 110000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}

vector<vi> e;
ll k, ans;
void rec(int c, int p, int d = 0){
	int cld = 0, cnt = d == 0 ? k - 1 : k - 2;
	for(int i : e[c]) if(i != p) cld++;
	if(cld <= cnt){
		ans *= C(cnt, cld) * f[cld] % mod;
		ans %= mod;
		for(int i : e[c]) if(i != p) rec(i, c, d + 1);
	}
	else ans = 0;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	
	int n; cin >> n >> k;
	e.resize(n);
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	ans = k;
	rec(0, 0);
	cout << ans << endl;
	return 0;
}

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

int R;

int main () {
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


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

int main(){
  char c;
  cin >> c;
  if(c == 'a'|| c=='e'||c=='i'||c=='o'||c=='u'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3560
import itertools

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]

answer = 0

nums=[]
for i in range(1, M+1):
    nums.append(i)

for balls in itertools.combinations_with_replacement(nums, N):
    score = 0
    test = list(balls)
    for i in range(Q):
        if test[abcd[i][0]-1] + abcd[i][2] == test[abcd[i][1]-1]:
            score += abcd[i][3]
    if score > answer:
        answer = score

print(answer)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    int x; cin >> x;
    if (x==0) cout << '1' << endl;
    else cout << '0' << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int a[3];

void input(){
    for(int i=0;i<3;i++) cin >> a[i];
    sort(a, a+3);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    if((a[1]-a[0])%2) cout << a[2]-a[1]+(a[1]-a[0]-1)/2+2 << endl;
    else cout << a[2]-a[1]+(a[1]-a[0])/2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n;
  int a[1000];
  int i,j,k;
  int temp;

  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
  }

  
  for (i=0; i<n; i++) {
    if (i!=n-1) printf("%d ",a[i]);
    else printf("%d\n",a[i]);
  }
  
  for (i=1; i<n; i++) {
    temp=a[i];
    j=i-1;
    while (j>=0 && a[j]>temp) {
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=temp;
    for (k=0; k<n; k++) {
      if (k!=n-1) printf("%d ",a[k]);
      else printf("%d\n",a[k]);
    }
  }
  return 0;
}

Measured memory_bytes: 604
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int id { get; set; }
    public bool froma { get; set; }
    public int x { get; set; }
}

public class P2
{
    public int x1 { get; set; }
    public int id1 { get; set; }
    public int x2 { get; set; }
    public int id2 { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());

        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var ps = new P[n * 2];
        var p = 0;
        var d = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            ps[p++] = new P { id = i, x = a[i], froma = true };
            ps[p++] = new P { id = i, x = b[i] };
            if (d.ContainsKey(a[i])) d[a[i]]++;
            else d[a[i]] = 1;
            if (d.ContainsKey(b[i])) d[b[i]]++;
            else d[b[i]] = 1;
        }
        var dmax = d.Max(x =>x.Value);
        if (dmax > n) { Console.WriteLine("No"); goto exit; }
        Console.WriteLine("Yes");
        getAns(n, ps);
    exit:;
    }
    static void getAns2 (List<P2 > fa, List<P2 > fb, int[] ans )
    {
        var imax = fa.Count();
        for (int i = 0; i < imax; i++)
        {
            if (fa[i].x1 == fb[i].x1 | fa[i].x2 == fb[i].x2)
            {
                ans[fa[i].id1] = fb[i].x2;
                ans[fa[i].id2] = fb[i].x1;
            }
            else
            {
                ans[fa[i].id1] = fb[i].x1;
                ans[fa[i].id2] = fb[i].x2;
            }
        }
    }
    static void getAns (int n, P[] ps)
    {
        var fa = new List<P2>();
        var fb = new List<P2>();
        var ans = new int[ n];
        ps = ps.OrderBy(x => x.x).ToArray();
        for (int i = 0; i < n; i++)
        {
            var a = ps[i];
            var b = ps[i + n];
            if (a.froma && !b.froma) ans[a.id] = b.x;
            else if (!a.froma && b.froma) ans[b.id] = a.x;
            else if (a.froma && b.froma) fa.Add(new P2 { id1 = a.id, x1 = a.x, id2 = b.id, x2 = b.x });
            else fb.Add(new P2 { id1 = a.id, x1 = a.x, id2 = b.id, x2 = b.x });
        }
        if (fa.Count() > 0) getAns2(fa, fb,ans);
        Console.WriteLine(string.Join(" ",ans));
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

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

	int n;
	cin >> n;
	int cnt = 0;
	erep(i, 1, n)
	{
		int curr = i, hoba = 0;

		while (curr)
		{
			curr /= 10;
			hoba++;
		}

		if (hoba & 1)
			cnt++;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int examin_money(int N, int SUM) {
	for (int i = 0; i <= N; i++) {
		if (10000 * i > SUM) {
			break;
		}
		for (int j = 0; j <= N - i; j++) {
			if (10000 * i + 5000 * j > SUM) {
				break;
			}
			int total = 10000 * i + 5000 * j + 1000 * (N - i - j);
			if (total == SUM) {
				printf("%d %d %d\n", i, j, N - i - j);
				return 0;
			}
		}
	}
	printf("%d %d %d\n", -1, -1, -1);
	return 0;
}

int main(void) {
	int n, sum;
	scanf("%d %d", &n, &sum);
	examin_money(n, sum);
	return 0;
}

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


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    ans = 0

    # See:
    # https://www.youtube.com/watch?v=JTH27weC38k
    # https://atcoder.jp/contests/jsc2019-qual/submissions/7107452

    # Key Insight
    # 2つの整数の順序対(i, j)の選び方
    # 同じブロックにある/異なるブロックにある で場合分け

    # 同じブロックにある
    # Bi > Bjとなる組み合わせを全探索
    for i in range(n - 1):
        count = 0

        for j in range(i + 1, n):
            if a[i] > a[j]:
                count += 1

        # 一つのブロックにある組み合わせのk倍
        ans += count * k
        ans %= mod

    # 別のブロックにある
    for i in range(n):
        count = 0

        for j in range(n):
            if a[i] > a[j]:
                count += 1

        # k個のブロックから2個選ぶ（kC2）
        ans += count * (k * (k - 1) // 2)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

    int n1 = (N / 4) + 1, n2 = (N / 7) + 1;

    REP(i, n1){
        REP(j, n2){
            int num = i * 4 + j * 7;
            if (num == N){
                cout << "Yes" << endl;
                exit(0);
            }
        }
    }

    cout << "No" << endl;

}

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

using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::endl;
using std::ios_base;
using std::unordered_map;
using std::cerr;
using std::string;
using std::to_string;
using std::max;
using std::min;

const long long INF = 1e18;
const long long MOD = 1e9 + 7;

vector<vector<long long>> dp;
vector<vector<long long>> g;
vector<bool> used;

void dfs(long long u) {
    used[u] = 1;
    dp[u][0] = 1;
    dp[u][1] = 1;
    for (long long v : g[u]) {
        if (!used[v]) {
            dfs(v);
            dp[u][1] *= dp[v][0];
            dp[u][1] %= MOD;
            dp[u][0] *= (dp[v][1] + dp[v][0]);
            dp[u][0] %= MOD;
        }
    }
}

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

    long long n;
    cin >> n;
    dp.resize(n, vector<long long>(2));
    used.resize(n);
    g.resize(n);
    for (long long i = 0; i < n - 1; i++) {
        long long a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
            ans += dp[i][0] + dp[i][1];
            ans %= MOD;
        }
    }
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)
using ipair = pair<int,int>;

int main(){
    int n;
    cin >> n;
    if(n%10==3) cout << "bon"<<endl;
    else if (n%10<=1||n%10==6||n%10==8) cout << "pon"<<endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3636
import Data.Ord
import Data.List
 
main :: IO ()
main = do
    _ <- getLine
    list <- map read . words <$> getLine
    let (alice, bob) = execGame (sortOn Down list) (0, 0)
    putStrLn $ show $ alice - bob 
 
execGame :: [Int] -> (Int, Int) -> (Int, Int)
execGame [] (a, b) = (a, b)
execGame [x] (a, b) = (a + x, b)
execGame (x : y : rest) (a, b) = execGame rest (a + x, b + y)

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
///////////////////////

int const N = 241;
int const M = 1e7 + 41;

int l[M], a[N], n, b[M];
vector<int> p;
int g[N][N], w[N], lp[N];
vector<int> pt[2];

void sieve(){
	fr(i, 2, M){
		if(l[i] == 0){
			l[i] = i;
			p.push_back(i);
		}
		for(int j=0;j<sz(p) && p[j] * 1LL * i < M && p[j] <= l[i]; ++j){
			l[p[j] * i] = p[j];
		}
	}
}

bool isPrime(int v){
	if(v != 2 && l[v] == v) return true;
	else return false;
}

void clear(){
	fr(i, 0, N) w[i] = 0;
}

bool dfs(int u){
	w[u] = 1;
	fr(i, 0, sz(pt[1])){
		if(g[u][i]){
			if(lp[i] == -1 || !w[lp[i]] && dfs(lp[i])){
				lp[i] = u;
				return true;
			} 
		}
	}
	return false;
}

void solve(){
	sieve();
	cin >> n;
	fr(i, 0, n) cin >> a[i];
	fr(i, 0, n) b[a[i]] = 1;
	fr(i, 1, M){
		if(b[i] != b[i-1]){
			pt[(i&1)].push_back(i);
		}
	}
	fr(i, 0, sz(pt[0])) fr(j, 0, sz(pt[1])){
		int dist = abs(pt[0][i] - pt[1][j]);
		if(isPrime(dist)) g[i][j] = 1;
	}
	fr(i, 0, sz(pt[1])) lp[i] = -1;
	fr(i, 0, sz(pt[0])){
		clear();
		dfs(i);
	}
	int ans = 0;
	int o = sz(pt[1]);
	int e = sz(pt[0]);
	fr(i, 0, sz(pt[1])){
		if(lp[i] != -1) ++ans;
	}
	e -= ans;
	o -= ans;

	ans += (e / 2) * 2;
	ans += (o / 2) * 2;
	e %= 2;
	o %= 2;
	if(o + e > 0) ans += 3;

	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 80748
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = LI()
B = LI()
if sum(A) < sum(B):
    print(-1)
    exit()

cnt = 0
need = 0
mochi = []
for i in range(N):
    a = A[i]
    b = B[i]
    if a < b:
        cnt += 1
        need += b - a
    else:
        mochi.append(a - b)

mochi.sort()
# print(cnt, need)
# print(mochi)

while need > 0:
    p = mochi.pop()
    need -= p
    cnt += 1

print(cnt)



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


int main(){
  int N;  cin >> N;
  long long ten = 1;
  long long nine = 1;
  long long eight = 1;
  for(int i=0;i<N;i++){
    ten *= 10;  ten %= 1000000007;
    nine *= 9;  nine %= 1000000007;
    eight *= 8; eight %= 1000000007;
  }
  long long ans = ten + eight;
  ans %= 1000000007;
  nine *= 2;
  nine %= 1000000007;
  ans -= nine;
  if(ans < 0) ans += 1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 3604
from bisect import bisect_left, bisect_right
n = int(input())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))

ans = 0
for i in b:
    x = bisect_left(a, i)
    y = n - bisect_right(c, i)
    ans += x * y
print(ans)

Measured memory_bytes: 23476
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();   
      	long ans = 0;
      	for(int i=1;i<=n;i++){
          long t = n / i;
          long l = i * t * ( t+1 ) / 2;
          ans += l;
        }
      	System.out.println(ans);
    }
}


Measured memory_bytes: 27180
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;
const ll INF = 1LL<<50;

int main(){

int N;
ll W;
cin>>N>>W;
ll w[N+1],v[N+1];
ll dp[100001][N+1];
rep3(i,N){
    cin>>w[i]>>v[i];
}

rep(i,N+1){
    dp[0][i]=0;
}
rep3(i,100000){
    rep(j,N+1){
        dp[i][j]=INF;
    }
}
ll ans=0;
rep3(j,N){
    rep3(i,100000){
        
        if(i>=v[j]){
            
            dp[i][j]=min(dp[i][j-1],dp[i-v[j]][j-1]+w[j]);
            if(dp[i][j]<=W){
                ans=max(ans,i);
            }
        }
        else{
            dp[i][j]=dp[i][j-1];
        }

    }
}


cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 82496
from bisect import bisect_right

rectangles = [(h ** 2 + w ** 2, h, w) for h in range(1, 151) for w in range(1, 151) if h < w]
rectangles.sort()

while True:
    h, w = map(int, input().split())
    if not h and not w:
        break

    gt_rectangle = rectangles[bisect_right(rectangles, (h ** 2 + w ** 2, h, w))]
    print(gt_rectangle[1], gt_rectangle[2])

Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  	
  ll a,b;
  cin>>a>>b;
  if(a>b)
  {
    cout<<-1<<endl;
    return 0;
  }
  ll val1,val2;
  val1=ceil(a/0.08);
  val2=ceil(b/0.1);
  if(val1>val2)
  {
    if(floor(val1*0.1)>b)
    {
      cout<<-1<<endl;
    }
    else
      cout<<val1<<endl;
  }
  else  
  {
  
    if(floor(val2*0.08)>a)
    {
      cout<<-1<<endl;
    }
    else
      cout<<val2<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a < b){
        cout << 0;
    }
    else
    {
        cout << 10;
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    vector<ll> seq={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k; cin>>k;
    cout<<seq[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

// const int maxn = 
// const int mo = 1e9 + 7;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, l;
	cin >> n >> l;

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

	if (!(1-l > 0 && 1-l <= n)) {
		if (abs(l) < abs(n+l-1))
			ans -= l;
		else
			ans -= n+l-1;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int dist = 1;
        int count = 0;
        int[] ans = new int[n];
        int[] aaa = new int[n];
        int[] check = new int[n];
        int mod = 0;
        int sub = 0;

        while (true) {
            count++;
            dist = a[dist - 1];
            if (k == (long) count) {
                System.out.println(dist);
                return;
            }
            check[dist - 1] ++;    
            if (check[dist - 1] == 2) {
                sub = ans[dist - 1];
                mod = count - ans[dist - 1];
                break;
            }
            ans[dist - 1] = count;
            aaa[count] = dist;
        }

        System.out.println(aaa[(int) (((k - sub) % mod) + sub)]);

    }
}


Measured memory_bytes: 59972
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
#include <iomanip>
using namespace std;
// type alias
typedef long long LL;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))

// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');

// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpf(args...) if(TRACE) { fprintf(stderr, ##args); putchar('\n'); }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
template<class Iter> void dumpc(Iter begin, Iter end) { if (TRACE) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } }

// $ cp-batch Palace | diff Palace.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Palace.cpp && ./a.out

/*
 
 1/20/2019
 
 15:32-
 
 */

const int MAX_N=1e6+1;
LL H[MAX_N];
int N,T,A;

void solve() {
  vector<pair<double,int>> X;
  REP(i,N) X.emplace_back(abs(A-(T-0.006*H[i])),i);
  sort(ALL(X));
  cout<<X.front().second+1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>T>>A;
  REP(i,N) cin>>H[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
to_white = [0] * n
to_black = [0] * n
for i in range(n):
    if s[i] == '#':
        if i == 0:
            to_white[i] = 1
        else:
            to_white[i] = to_white[i-1] + 1
    else:
        if i == 0:
            to_white[i] = 0
        else:
            to_white[i] = to_white[i-1]
for i in reversed(range(n)):
    if s[i] == '.':
        if i == n-1:
            to_black[i] = 1
        else:
            to_black[i] = to_black[i+1] + 1
    else:
        if i == n-1:
            to_black[i] = 0
        else:
            to_black[i] = to_black[i+1]
ans = 10**100
for i in range(n):
    ans = min(ans, to_white[i] + to_black[i] - 1)
print(ans)


Measured memory_bytes: 12792
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int ans_order[100010];
    int A;

    cin >> N;

    for(int i=1;i<=N;i++)
    {
        cin >> A;
        ans_order[A-1] = i;
    }

    for(int idx=0;idx<N;idx++)
    {
        cout << ans_order[idx];

        if(idx == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
        

    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int f(int x,int y,int z){
	return (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x);
}

void testcase(){
	int n;
	cin >> n;
	vector<int> got(n+10,0);
	for(int x{1};x < 100;x++){
		for(int y{1};y < 100;y++){
			for(int z{1};z < 100;z++){
				if(f(x,y,z) <= n){
					got[f(x,y,z)]++;
				}
			}
		}
	}
	for(int i{1};i <= n;i++){
		cout << got[i] << "\n";
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3652
# coding: utf-8


def solve(*args: str) -> str:
    l, r, d = map(int, args[0].split())
    count = 0
    for i in range(l, r+1):
        if i % d == 0:
            count += 1
    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9108
# coding: utf-8

n_cus, n_bus, n_wai = map(int, input().split())
l_arr = [int(input()) for i in range(n_cus)]
l_arr.sort()

n_time_angry = 0
n_now_sheet = n_bus
l_waiting_cus = []
n_need_bus = 0

for arr in l_arr:
    if arr <= n_time_angry and n_now_sheet > 0:
        n_now_sheet -= 1
    else:
        n_time_angry = arr + n_wai
        n_now_sheet = n_bus - 1
        n_need_bus += 1
        
print(n_need_bus)

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

double dp[3005][3005];
int main(){
    int i,j;
    int N;
    cin >> N;
    double p[N];
    for(i=0;i<N;i++)cin >> p[i];
    dp[0][0]=1.00000;
    for(j=0;j<N;j++){
        for(i=0;i<j+1;i++){
            dp[i][j+1]+=dp[i][j]*(1-p[j]);
            dp[i+1][j+1]+=dp[i][j]*p[j];       
        }
    }
    double ans=0.00000;
    for(i=N/2+1;i<N+1;i++)ans+=dp[i][N];
    cout << fixed << setprecision(16);
    cout << ans << endl;
}

Measured memory_bytes: 70016
program prob6
    implicit none
    integer(8) :: N, x
    integer(8), allocatable :: A(:)
    integer(8) :: i, ans
    read(*,*) N, x
    allocate(A(N))
    read(*,*) A

    ans = max(A(1) - x, 0)
    A(1) = min(A(1), x)
    do i = 2, N
        if(A(i) + A(i-1) > x) then
            ans = ans + A(i) + A(i-1) - x
            A(i) = x - A(i-1)
        end if
    end do
    write(*,*) ans




    deallocate(A)

    stop
contains
end program prob6

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
ll i,j;
int main()
{IOS;
int t;
t=1;
while(t--)
{ ll a;
cin>>a;
ll temp = pow(a,2)+ pow(a,3);
cout<<a+temp<<endl;
}
return 0;}






Measured memory_bytes: 4072
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

ck = [0]*(N-2)
ans = 0
for i in range(N-2):
  j = i + 1
  k = N - 1
  while j < k:
    if L[i]-L[j]-L[k] < 0:
      ans += k-j
      j += 1 
    else:
      k -=1
  
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll t = N;
	ll sum = 0;
	while (t > 0) {
		sum += t % 10;
		t /= 10;
	}
	if (N % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	string O,E;
	cin >> O >> E;
	if(O.size()==E.size()){
		for(int i=0;i<O.size();i++){
			cout << O[i];
			cout << E[i];

		}
			cout << endl;
	}else{
		for(int j=0;j<E.size();j++){
			cout << O[j];
			cout << E[j];
		}
		cout << O[E.size()];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,C,K;
	cin >> N >> C >> K;
	ll an = 1;
	
	vector<ll> A(N);
	
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		
	}
	sort(A.begin(), A.end());
	ll t = A.at(0);
	ll ni = 1;
	for (int i = 1; i < N; i++) {
		if (ni < C && A.at(i) - t <= K) {
			ni++;
		}
		else {
			t = A.at(i);
			ni = 1;
			an++;
		}
	}
	cout << an << endl;
}



Measured memory_bytes: 1024
import math


def divisor(div, n):
    # 約数
    ini = 1 if n % 2 else 2
    for i in range(ini, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            div.append([i, n // i])


def main():
    N = int(input())
    div = []
    divisor(div, N)
    print(max(int(math.log10(div[-1][0]) + 1),
              int(math.log10(div[-1][1]) + 1)))
    return


main()


Measured memory_bytes: 3060
#include <stdio.h> 
int main(void){ 
    int m,f,r; 
    while(scanf("%d %d %d",&m,&f,&r),m+f+r!=-3){ 
    if(m==-1||f==-1) printf("F\n"); 
    else if(m+f>=80) printf("A\n"); 
    else if(m+f>=65) printf("B\n"); 
    else if(m+f>=50) printf("C\n"); 
    else if(m+f>=30){ if(r>=50)    
    printf("C\n"); 
    else    printf("D\n"); 
    } 
    else printf("F\n");
    } return 0; 
    
}


Measured memory_bytes: 2036
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1000005
#define mod 998244353
using namespace std;

int n, m, inv[N], fac[N], ifac[N];

inline int qpow(int x, int t) {
  int res = 1;
  while (t) {
    if (t & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod; t >>= 1;
  }
  return res;
}

inline int C (int n, int m) {
  return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main() {
  scanf("%d%d", &n, &m);
  inv[0] = inv[1] = 1;
  fac[0] = fac[1] = 1;
  ifac[0] = ifac[1] = 1;
  for (int i = 2; i < N; ++i) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
  }
  int mn = min(n, m), ans = 0;
  for (int i = 1; i <= mn; ++i)
    ans = (ans + 1ll * C(i << 1, i) * C(n + m - (i << 1), n - i)) % mod;
  ans = 1ll * ans * qpow(C(n + m, n), mod - 2) % mod * ifac[2] % mod;
  printf("%d\n", (ans + max(n, m)) % mod);
  return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i =0;i<N;i++){
  cin >> v.at(i);
}
int c =0;
for(int i =N-1;i>0;i--){
  if(v.at(i-1)-v.at(i)>1){
    c+=2;
  }
  else if(v.at(i-1)-v.at(i)==1){
    v.at(i-1)--;
  }

  
}
if(c<=1){
  cout << "Yes" <<endl;
}
else{
  cout << "No" <<endl;
}

}

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

k_max = (n-1)*(n-2)//2
if k > k_max:
	print(-1)
	exit()

m = (n-1) + k_max - k
print(m)

for i in range(n-1):
	print(1, i+2)
ptr1 = 2
ptr2 = 3
for _ in range(k_max - k):
	print(ptr1, ptr2)
	if ptr2 < n:
		ptr2 += 1
	else:
		ptr1 += 1
		ptr2 = ptr1 + 1


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double d = scan.nextInt();
		double t = scan.nextInt();
		double s = scan.nextInt();

		if(d / s <= t) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

using namespace std;

int main() {
	int a,b;
	char op;
	while( true ) {
		scanf( "%d %c %d", &a, &op, &b );
		if( op == '?' ) { break; }
		int ans;
		switch( op ) {
			case '+': ans = a + b; break;
			case '-': ans = a - b; break;
			case '*': ans = a * b; break;
			case '/': ans = a / b; break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
#include <stack>
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
	stack<int> s;
	string a;
	int b;

	while (cin >> a) {
		if (a == "+") {
			b = s.top();
			s.pop();
			b += s.top();
			s.pop();
			s.push(b);
		}
		else if (a == "-") {
			b = s.top();
			s.pop();
			b -= s.top();
			s.pop();
			s.push(-b);
		}
		else if (a == "*") {
			b = s.top();
			s.pop();
			b *= s.top();
			s.pop();
			s.push(b);
		}
		else if (cin.eof()) break;
		else {
			s.push(atoi(a.c_str()));
		}
	}
	cout << s.top() << endl;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
#define bck \
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    vector<char> v;
    int t;
    cin >> s;
    if(s=="ARC") cout << "ABC" << "\n";
    else cout << "ARC" << "\n";


    bye;
 }
    	


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec,x)  (find(all(vec),x)!=(vec).end())
#define present(myset,x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x,y) cout<<x<<" "<<y<<endl;
#define trace3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9+7;
const int MAX = 1e5+5;
using namespace std;

long double dp[3001][3001];          // j heads upto index i

int main()
{
    FAST_IO;
    int n;
    cin>>n;
    long double a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    dp[1][1]=a[1];
    dp[1][0]=(1.0)-a[1];

    for(int i=2;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0){
                dp[i][0]=dp[i-1][j]*(1.0-a[i]);
            }
            else
            dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1.0-a[i]);
            //cout<<dp[i][j]<<" ";
        }
        //nl;
    }
    //nl;
    long double ans=0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(12)<<ans;


    return 0;

}

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

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

  for (int i = 0; i < N; i++) {
    string X;
    cin >> X;
     
    if (X=="Y") {
      cout << "Four" << endl;
      break;}
    
    else if (i== N-1 && X !="Y") {
      cout << "Three" << endl;}
    
   }
      
}

Measured memory_bytes: 3584
#include <iostream>
#define NMAX 300005
using namespace std;

int w[NMAX], e[NMAX];
int n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        char c;
        cin >> c;
        w[i] = w[i - 1];
        e[i] = e[i - 1];
        if (c == 'W')
            w[i]++;
        else
            e[i]++;
    }

    int minim = n;
    for (int i = 1; i <= n; i++)
    {
        int aici = w[i - 1] + e[n] - e[i];
        minim = min(minim, aici);
    }
    cout << minim;

    return 0;
}


Measured memory_bytes: 2688
{-# LANGUAGE BangPatterns #-}
import           Control.Monad (replicateM)
import           Data.List     (foldl')

main :: IO ()
main = do
  s <- getLine
  q <- readLn
  qs <- replicateM q getQuery
  putStrLn $ solve s qs

data Query = Reverse | Add Bool Char

getQuery :: IO Query
getQuery = do
  (t:xs) <- words <$> getLine
  if t == "1"
    then return Reverse
    else let [f, c] = xs in return $ Add (f == "1") (head c)

solve :: String -> [Query] -> String
solve s qs = toList $ foldl' g (fromList s) qs
  where g !xs Reverse   = rev xs
        g !xs (Add f c) = add c f xs

data DoubleList a = DoubleList [a] [a] Bool
  deriving Show

fromList :: [a] -> DoubleList a
fromList xs = DoubleList xs [] True

toList :: DoubleList a -> [a]
toList (DoubleList xs ys True)  = xs ++ reverse ys
toList (DoubleList xs ys False) = ys ++ reverse xs

rev :: DoubleList a -> DoubleList a
rev (DoubleList xs ys f) = DoubleList xs ys $ not f

add :: a -> Bool -> DoubleList a -> DoubleList a
add x True (DoubleList xs ys True)   = DoubleList (x:xs) ys True
add x True (DoubleList xs ys False)  = DoubleList xs (x:ys) False
add x False (DoubleList xs ys True)  = DoubleList xs (x:ys) True
add x False (DoubleList xs ys False) = DoubleList (x:xs) ys False


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

int main(){
  int n, t, a;
  cin >> n >> t >> a;
  int h[n];
  int min = 10000000;
  int res;

  for(int i=1; i<=n; ++i){
    cin >> h[i];
    int d = abs((t*1000-h[i]*6)-a*1000);
    if(d < min){
      min = d;
      res = i;
  }
  }
    cout << res;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N, K = map(int, readline().split())
LR = [list(map(int, readline().split())) for _ in range(K)]

dp = [0]*(N+1)
dp[1] = 1


MOD = 998244353
cnt = 0
event = [0]*(N+1)
for i in range(1, N+1):
    cnt = (cnt + event[i])%MOD
    dp[i] = (dp[i]+cnt)%MOD
    for l, r in LR:
        r += 1
        if i+l <= N:
            event[i+l] = (event[i+l]+dp[i])%MOD
        if i+r <= N:
            event[i+r] = (event[i+r]-dp[i])%MOD
print(dp[N])

Measured memory_bytes: 71360
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,now,next,c;
  cin >> N;
  vector<int>a(N);
  for (int i=0;i<N;i++){
    cin >> a.at(i);
  }
  now = a.at(0);
  c = -1;
  int i = 1;
  while (i<100001){
    if (now == 2){
      c = i;
      break;
    }else{
      next = a.at(now-1);
      now = next;
      i++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 640
#ABC122-B
s = input()
atgc = set(['A','T','G','C'])
cnt = 0
acgt_len = []
for i in range(len(s)):
    if s[i] in atgc:
        cnt += 1
        
    else:
        acgt_len.append(cnt)
        cnt = 0
        
acgt_len.append(cnt)

print(max(acgt_len))

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

#define MAX 2000
#define LRMAX 1999

using namespace std;

// 配列a, 行の大きさl, 座標(i, j), 向きd から照らされるマスの個数を調べる
// 向きは0が正, 1が負
// 正ならばjを1ずつ増加させ、jがlに到達するか、障害物に当たるまで進む
// 負ならばjを1ずつ減少させ、jが-1に到達するか、障害物に当たるまで進む
// 
int light_1d(int (*a)[MAX], int l, int i, int j, int d){
  int s = 0;

  while(true){
    if(d==0){
      j++;
      if(j>l-1 || a[i][j] == 1) break;
      s++;
    }
    else if(d==1){
      j--;
      if(j<0 || a[i][j] == 1) break;
      s++;
    }
  }

  return s;
}

// 四方向全ての照らされるマスの個数の和を返す
// これまでの最大の個数を更新できないとわかった場合には0を返す
int light_4d(int (*a)[MAX], int (*a_flip)[MAX], int H, int W, int i, int j, int ans){
  int center = 1;

  int up = light_1d(a_flip, H, j, i, 1);
  if(H-(i+1)<=ans-(center+LRMAX+up)) return 0;
  int down = light_1d(a_flip, H, j, i, 0);
  if(W<=ans-(center+up+down)) return 0;

  int left = light_1d(a, W, i, j, 1);
  if(W-(j+1)<=ans-(center+up+down+left)) return 0;
  int right = light_1d(a, W, i, j, 0);
  if(center+up+down+left+right<=ans) return 0;

  int sum = center + up + down + left + right;

  return sum;
}

int main(void){

  int H, W;
  string S;
  int a[MAX][MAX], a_flip[MAX][MAX];
  int result, ans = 0;

  cin >> H >> W;
  for(int i=0; i<H; i++){
    cin >> S;
    for(int j=0; j<W; j++){
      if(S[j]=='.') a[i][j] = 0;
      else if(S[j]=='#') a[i][j] = 1;
      a_flip[j][i] = a[i][j];
    }
  }

  // 照らされるマスの最大の個数を調べる
  // 手順
  // 左上のマスから順に調べる
  // 左上右下の順にその方向に照らすことができるマスを数える
  // それらの和が現在の最大の個数以上ならば保存する
  // 到達したマスが端または障害物である場合は数えることを止め、次の方向を調べる
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(a[i][j]==1) continue;
      if((result = light_4d(a, a_flip, H, W, i, j, ans))!=0) ans = result;
      if(ans==3999) break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

H,W=map(int,input().split())
A=[input().strip() for i in range(H)]

mod=998244353

# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,21):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(20,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

COMBI=[[-1]*21 for i in range(21)]
def Combi(a,b):
    if COMBI[a][b]!=-1:
        return COMBI[a][b]
    
    if 0<=b<=a:
        COMBI[a][b]=FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
        return COMBI[a][b]
    else:
        COMBI[a][b]=0
        return 0

M=max(H,W)+1
RA=[[-1]*M for i in range(M)]
def rect(H,W):
    if H==W==0:
        return 1
    if RA[H][W]!=-1:
        return RA[H][W]
    
    DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
    DP[0][0][0]=1
    DP[0][0][1]=1

    for h in range(H+1):
        for w in range(W+1):
            for nexth in range(h+1,H+1):
                DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
                DP[nexth][w][0]%=mod

            for nextw in range(w+1,W+1):
                DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
                DP[h][nextw][1]%=mod

    RA[H][W]=RA[W][H]=sum(DP[H][W])%mod*FACT[H]*FACT[W]%mod

    return RA[H][W]

CA=[[-1]*(W+1) for i in range(H+1)]
def calc(h,w):
    if CA[h][w]!=-1:
        return CA[h][w]
    
    RET=0
    
    for bh in range(h+1):
        for bw in range(w+1):
            RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
            #print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
            RET%=mod

    CA[h][w]=RET%mod
    return CA[h][w]

for i in range(H+1):
    for j in range(W+1):
        calc(i,j)

ANS=rect(H,W)

for i in range((1<<H)-1):
    for j in range((1<<W)-1):
        okflag=1
        for h in range(H):
            if i & (1<<h)!=0:
                continue
            coinc=""
            dif=0
            for w in range(W):
                if j & (1<<w)!=0:
                    continue

                if coinc=="":
                    coinc=A[h][w]
                elif A[h][w]!=coinc:
                    dif=1
                    break

            if dif==0:
                okflag=0
                break

        if okflag==0:
            continue

        okflag=1
        for w in range(W):
            if j & (1<<w)!=0:
                continue
            coinc=""
            dif=0
            for h in range(H):
                if i & (1<<h)!=0:
                    continue

                if coinc=="":
                    coinc=A[h][w]
                elif A[h][w]!=coinc:
                    dif=1
                    break
                
            if dif==0:
                okflag=0
                break

        if okflag==0:
            continue

        # i, jのうち、0の部分は決定済み. 1の部分に自由度がある.
        HR=WR=0
        for h in range(H):
            if i & (1<<h)!=0:
                HR+=1
        for w in range(W):
            if j & (1<<w)!=0:
                WR+=1

        ANS+=CA[HR][WR]
            
        #ANS%=mod

        
print(ANS%mod)

Measured memory_bytes: 68956
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

template<typename T>
using point = tuple<uint32_t, T, T>;

template<typename T>
class KdTree {
private:
    struct node {
        point<T> p;
        node *l, *r;
        node(const point<T> &p) : p(p), l(nullptr), r(nullptr) {}
    };

    node *root;

    template<typename Iter>
    node *construct(Iter points_begin, Iter points_end, bool x) {
        uint32_t n = points_end - points_begin;
        if (n == 0) return nullptr;

        if (x) sort(points_begin, points_end, [](const point<T> &lhs, const point<T> &rhs){return get<1>(lhs) < get<1>(rhs);});
        else sort(points_begin, points_end, [](const point<T> &lhs, const point<T> &rhs){return get<2>(lhs) < get<2>(rhs);});

        node *nd = new node(points_begin[n/2]);
        nd->l = construct(points_begin, points_begin+n/2, !x);
        nd->r = construct(points_begin+n/2+1, points_end, !x);

        return nd;
    }

    void search(node *nd, T sx, T tx, T sy, T ty, bool x, vector<uint32_t> &vec) {
        if (nd == nullptr) return;

        if (sx <= get<1>(nd->p) && get<1>(nd->p) <= tx &&
            sy <= get<2>(nd->p) && get<2>(nd->p) <= ty) {
            vec.push_back(get<0>(nd->p));
        }

        if (x ? sx <= get<1>(nd->p) : sy <= get<2>(nd->p)) search(nd->l, sx, tx, sy, ty, !x, vec);
        if (x ? get<1>(nd->p) <= tx : get<2>(nd->p) <= ty) search(nd->r, sx, tx, sy, ty, !x, vec);

        return;
    }

public:
    KdTree(vector<point<T>> &points) : root(construct(points.begin(), points.end(), true)) {}

    void construct(uint32_t id, const point<T> &p) {
        root = insert(root, id, p, true);
        return;
    }

    void search(T sx, T tx, T sy, T ty, vector<uint32_t> &vec) {
        search(root, sx, tx, sy, ty, true, vec);
        return;
    }

};

int main() {
    int32_t n;
    scanf("%d", &n);

    vector<point<int32_t>> points(n);

    for (int32_t i = 0; i < n; i++) {
        int32_t x, y;
        scanf("%d %d", &x, &y);

        points[i] = make_tuple(i, x, y);
    }

    KdTree<int32_t> kdt(points);

    int32_t q;
    scanf("%d", &q);

    for (int32_t i = 0; i < q; i++) {
        int32_t sx, tx, sy, ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);

        vector<uint32_t> res;
        kdt.search(sx, tx, sy, ty, res);

        sort(res.begin(), res.end());

        for (uint32_t id : res) printf("%u\n", id);
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 31316
n = int(input())
s = input()

ans = 0

while ans <= len(s)//2:
    prev_s = ''
    for i in range(ans+1, len(s)//2+1):
        if s[:i] in s[i:]:
            prev_s = s[:i]
        else:
            ans = max(ans, len(prev_s))
            break
    else:
        ans = max(ans, len(prev_s))
    s = s[1:]
    if len(s) == 1:
        break

print(ans)


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

int main() {
    int N;
    std::string S;
    bool res = true;
    int cnt = 0;

    std::cin >> N;
    for(int i = 0; i < N; ++i) {
        std::cin >> S;
        if(S == "A") {
            ++cnt;
        } else if(S == "Un") {
            --cnt;
        }

        if(res && cnt < 0) {
            res = false;
        }
    }
    if(res && cnt == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 3164