akhauriyash/Code-Regression huggingface dataset:
S = int(input())
A = [S,]
n = 1
def calc1():
  global n
  while True:
    if A[n-1] % 2 == 0:
      A.append(int(A[n-1] /2))
    else:
      A.append(int(3*A[n-1] +1))
    if A[n] in set(A[0:n]):
      return n+1
    n += 1
      
print(calc1())


Measured memory_bytes: 3060
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>

#ifdef _MSC_VER
#define scanf scanf_s
#define KEYWAIT getchar();getchar();
#else
#define KEYWAIT
#endif

int main()
{
    long a,b,c,ans=0;

    std::cin >> a >> b >> c;

    if (a + b >= c) {
        std::cout << "Yes" << std::endl;
    }
    else
        std::cout << "No" << std::endl;
 

    KEYWAIT

    return 0;
}


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

using namespace std;

#define gc getchar_unlocked
#define foi(i,n) for(int i=0;i<n;i++)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fol(i,n) for(ll i=0;i<n;i++)
#define Fol(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double angle = abs(0.5*(60.0*h+m)-(6)*m);
    angle*=PI/180.0;
    double dist = sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(angle));   
    cout<<fixed<<setprecision(20)<<dist<<"\n";
    return 0;
}

Measured memory_bytes: 11252
fn read_input() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s);
    s
}

fn solve(s: String, t: String) {
    let mut v_s: Vec<_> = s.trim().chars().collect();
    let t_s: Vec<_> = t.trim().chars().collect();
    for _ in 0..s.len() {
        if v_s == t_s {
            println!("Yes");
            return;
        }
        let last = v_s.pop().unwrap();
        v_s.insert(0, last);
    }
    println!("No");
}

fn main() {
    solve(read_input(), read_input());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
vector<int> edge[maxn];
int n, a[maxn], res[maxn];
int dp[maxn];
void dfs(int now, int last = -1, int len = 0) {
	int pos = lower_bound(dp, dp+len, a[now]) - dp;
	int o = dp[pos];
	len = max(len, pos+1);
	//if (!len || a[now] > dp[len-1].back()) pos = len+1;
	//cerr << now << " : " << pos << '\n';
	dp[pos] = a[now];
	res[now] = len;
	for (int u : edge[now]) if (u != last) 
		dfs(u, now, len);
	dp[pos] = o;
}

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> a[i];
	for (int i = 1, a, b;i < n;++i) {
		cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	dfs(1);
	for (int i = 1;i <= n;++i)
		cout << res[i] << '\n';
}



Measured memory_bytes: 32772
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define PI (3.141592653589793)
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; }
using namespace std;

string s,t;
int dp[3010][3010];

signed main(){
    cin>>s>>t;
    rep(i,s.size()){
        rep(j,t.size()){
            if(s.at(i)==t.at(j))chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }
    string ans="";
    int i=(int)s.size(),j=(int)t.size();
    while(i>0 and j>0){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }else if(dp[i][j]==dp[i][j-1]){
            j--;
        }else{
            i--; j--;
            ans=s.at(i)+ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
 
void SieveOfEratosthenes(int n, bool prime[],
                         bool primesquare[], int a[])
{
    // Create a boolean array "prime[0..n]" and
    // initialize all entries it as true. A value
    // in prime[i] will finally be false if i is
    // Not a prime, else true.
    for (int i = 2; i <= n; i++)
        prime[i] = true;
 
    // Create a boolean array "primesquare[0..n*n+1]"
    // and initialize all entries it as false. A value
    // in squareprime[i] will finally be true if i is
    // square of prime, else false.
    for (int i = 0; i <= (n * n + 1); i++)
        primesquare[i] = false;
 
    // 1 is not a prime number
    prime[1] = false;
 
    for (int p = 2; p * p <= n; p++) {
        // If prime[p] is not changed, then
        // it is a prime
        if (prime[p] == true) {
            // Update all multiples of p
            for (int i = p * 2; i <= n; i += p)
                prime[i] = false;
        }
    }
 
    int j = 0;
    for (int p = 2; p <= n; p++) {
        if (prime[p]) {
            // Storing primes in an array
            a[j] = p;
 
            // Update value in primesquare[p*p],
            // if p is prime.
            primesquare[p * p] = true;
            j++;
        }
    }
}
 
// Function to count divisors
int countDivisors(int n)
{
    // If number is 1, then it will have only 1
    // as a factor. So, total factors will be 1.
    if (n == 1)
        return 1;
 
    bool prime[n + 1], primesquare[n * n + 1];
 
    int a[n]; // for storing primes upto n
 
    // Calling SieveOfEratosthenes to store prime
    // factors of n and to store square of prime
    // factors of n
    SieveOfEratosthenes(n, prime, primesquare, a);
 
    // ans will contain total number of distinct
    // divisors
    int ans = 1;
 
    // Loop for counting factors of n
    for (int i = 0;; i++) {
        // a[i] is not less than cube root n
        if (a[i] * a[i] * a[i] > n)
            break;
 
        // Calculating power of a[i] in n.
        int cnt = 1; // cnt is power of prime a[i] in n.
        while (n % a[i] == 0) // if a[i] is a factor of n
        {
            n = n / a[i];
            cnt = cnt + 1; // incrementing power
        }
 
        // Calculating number of divisors
        // If n = a^p * b^q then total divisors of n
        // are (p+1)*(q+1)
        ans = ans * cnt;
    }
 
    // if a[i] is greater than cube root of n
 
    // First case
    if (prime[n])
        ans = ans * 2;
 
    // Second case
    else if (primesquare[n])
        ans = ans * 3;
 
    // Third casse
    else if (n != 1)
        ans = ans * 4;
 
    return ans; // Total divisors
}
 
// Driver Program
int main()
{
    int n; cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i ++){
    	if (i & 1){
    		if (countDivisors(i) == 8) cnt++;
    	}
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long a, b;
  cin >> a >> b;
  long result = 0;
  if (a > b) {
    result += a;
    a--;
  } else {
    result += b;
    b--;
  }
  if (a > b) {
    result += a;
    a--;
  } else {
    result += b;
    b--;
  }
  cout << result << endl;
  return 0;
}


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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100000;
const int mod = 1000000007;

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}

//main_method-----------------------------------------------------------------------------------


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

    int n = input(), m = input();

    vector<vector<int> > edges;
    rep(i,0,m) edges.push_back({input()-1, input()-1, -input()});

    bool isnc = false;
    vector<int> dist(n, inf); dist[0] = 0;

    rep(i,0,n){
        rep(j,0,m){
            int frm = edges[j][0], to = edges[j][1], cost = edges[j][2];
            if(dist[frm] != inf && dist[to] > dist[frm] + cost){
                dist[to] = dist[frm] + cost;
                if(i == n-1 && to == n-1) isnc = true;
            }
        }
    }

    if(isnc) print("inf");
    else print(-dist.back());


    
}

Measured memory_bytes: 384
n = int(input())
X = list(map(int,input().split()))
h = int(n/2)
Xs = sorted(X)
m1 = Xs[h-1]
m2 = Xs[h]

for i in range(n):
  if X[i] <= m1:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 25620
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] taste = new int[n];
        int ans = 0;
        int eat = 0;
        int min = 1000000000;

        for(int i = 0;i < n;i++){
            taste[i] = l+i;
            ans += taste[i];
        }

        for(int i = 0;i < n;i++){
            int tmp = Math.abs(taste[i]);
            if(tmp < min){
                min = tmp;
                eat = i;
            }
        }

        System.out.println(ans-taste[eat]);
    }
}

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

using namespace std;

#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);

    int n,x,last=0,cnt=1,ans=0,i;
    cin>>n;
    for(i=1; i<=n; ++i)
    {
        cin>>x;
        if(x<=last)
            cnt++,last=x;
        else
            cnt=1,last=x;
        ans=max(ans,cnt);
    }
    cout<<ans-1;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main( String args[] ) {
        Scanner scan	= new Scanner( System.in );
		
        String W		= scan.nextLine().toUpperCase();
		
		int count = 0;
		while( true ) {
			String T = scan.next();
			if ( T.equals("END_OF_TEXT") ) {
				break;
			} else if ( T.toUpperCase().equals( W ) ) {
				count++;
				
			}
			
		}
		
		System.out.println( count );
		
	}
}

Measured memory_bytes: 18096
#include "bits/stdc++.h"
// #include <bits/stdc++.h>
using namespace std;
#include <atcoder/all> 
using namespace atcoder;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

  

int main(){
  int n, m;
  cin >> n >> m;
  dsu uf(n);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.merge(a, b);
  }

  int ans = uf.groups().size() - 1;
  cout << ans << endl;
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 8920
def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    
    ans=10**11
    for bit in range(1<<n):
        s=set()
        for i in range(n):
            if (bit>>i)&1:
                s.add(i)
                
        if len(s)!=k:
          continue       
        
        b=a.copy()
        M=0
        cost=0
        for i in range(n):
            if (i in s) and b[i]<=M:               
                cost+=M-b[i]+1
                b[i]=M+1
                M+=1
            else:
                M=max(M,b[i])
        ans=min(ans,cost)
        
    print(ans)
 
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

H,W=LI()
N=II()
INL=LI()

row = [0]*W
items = list(enumerate(INL, 1))
# print(items)
cur = 0
cnt = 0
for i in range(H):
    rn = range(W) if i%2 == 0 else reversed(range(W))
    for j in rn:
        row[j] = items[cur][0]
        cnt += 1
        # print("{} cur {} cnt:{}".format(items[cur][0], cur,cnt))
        if cnt >= items[cur][1]:
            cnt = 0
            cur += 1
    print(*row)


Measured memory_bytes: 44528
#include <stdio.h>
#include <math.h>

int main() {

  double d1,d2,d3,d4;
  int i,j,k,l,n;
  double x[1020] = {0};
  double y[1020] = {0};
  double z[1020] = {0};
  double o,p,q,max;
  max = -1;
  o=0;
  p=0;
  q=0;
  d1 = 0;
  d2 = 0;
  d3 = 0;
  d4 = 0;

  scanf("%d",&n);

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

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

  for(i=0; i<n;i++) {

    o = (x[i] - y[i]) * (x[i] - y[i]);
    p = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
    p = p*p;
    p = sqrt(p);
  
    d3 = d3 + p;
    d2 = d2+o;
    d1 = d1 + sqrt(o); 

    if(max < sqrt(o)) {
      max = sqrt(o);
    }

   
  }

  d2 = pow(d2,1.0/2);
  d3 = pow(d3,1.0/3);
  d4 = max;

  printf("%.11lf\n%.11lf\n%.11lf\n%.11lf\n" ,d1,d2,d3,d4);

  return 0;

}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::string s, t;
  std::cin >> s >> t;

  for (int64_t i = 0; i < n; i++) {
    std::cout << s[i] << t[i];
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
/// You just can't beat the person who never gives up
/// ICPC next year

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e3+5 ;

int n ,m ,u ,v ;
vector<int> adj[N] ,cur ,ans ;
bool vis[N] ;
void dfs(int p){
    if(vis[p] && cur[0]==p){
        if(!ans.size() || cur.size()<ans.size()) ans = cur ;
        return ;
    }
    if(vis[p]) return ;
    vis[p] = 1 ;
    cur.push_back(p);
    for(int ch:adj[p]) dfs(ch);
    cur.pop_back();
}
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
    }
    for(int i=1;i<=n;++i){
        memset(vis,0,sizeof vis);
        dfs(i);
    }
    if(!ans.size()) return cout << -1 ,0;
    cout << ans.size() << endl ;
    for(auto go:ans)printf("%d\n",go);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define int long long
#define rep(i,a,b) for (i=a;i<=b;i++)
typedef long long ll;
#define maxd 998244353
ll invfac[1000500],fac[1000500];
int n,m;

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

ll qpow(ll x,ll y)
{
    x%=maxd;y%=maxd;
    ll ans=1,sum=x;
    while (y)
    {
        int tmp=y%2;y/=2;
        if (tmp) ans=(ans*sum)%maxd;
        sum=(sum*sum)%maxd;
    }
    return ans;
}

void init()
{
    n=read();m=read();
    if (n<m) swap(n,m);
    int i;fac[0]=1;invfac[0]=1;
    for (i=1;i<=n+m;i++) fac[i]=(fac[i-1]*i)%maxd;
    invfac[n+m]=qpow(fac[n+m],maxd-2);
    for (i=n+m-1;i>=1;i--) invfac[i]=(invfac[i+1]*(i+1))%maxd;
    //for (i=1;i<=n+m;i++) cout << invfac[i] << " ";cout << endl;
}

ll C(int a,int b)
{
    if (a>b) return 0;
    return ((fac[b]*invfac[a])%maxd*invfac[b-a])%maxd;
}

void work()
{
    ll ans,tmp=0;int i;
    for (i=1;i<=m;i++)
    {
        tmp=(tmp+(C(i,2*i)*C(n-i,n+m-2*i)))%maxd;
        //cout << tmp << endl;
    }
    //cout << tmp << endl;
    tmp=(tmp*qpow(C(n,n+m),maxd-2))%maxd;
    ans=((tmp*qpow(2,maxd-2))%maxd+n)%maxd;
    ans=((ans%maxd)+maxd)%maxd;
    printf("%lld",ans);
}

signed main()
{
    init();
    work();
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int INF = 1000000000 + 8;
constexpr int ceil(int a, int b)
{
    return (a + b - 1) / b;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(16);

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

    const int x_sum = accumulate(x.begin(), x.end(), 0LL);
    const array<int, 2> ps = {x_sum / n, ceil(x_sum, n)};

    int ans = INF;
    for (auto &&p : ps)
    {
        int now_ans = 0;
        for (auto &&i : x)
        {
            now_ans += pow(i - p, 2);
        }
        ans = min(now_ans, ans);
    }

    cout << ans << endl;
}


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

int G[26][26];
int deg[26];
bool done[26];

void dfs(int s) {
  done[s] = true;
  for(int i=0; i<26; i++) {
    if(!done[i] && G[s][i]) dfs(i);
  }
}

int main() {
  int n, a, b;
  string str;
  
  while(cin >> n, n) {
    for(int i=0; i<26; i++) {
      for(int j=0; j<26; j++) {
	G[i][j] = 0;
      }
      done[i] = true;
      deg[i] = 0;
    }

    for(int i=0; i<n; i++) {
      cin >> str;
      a = str[0]-'a';
      b = str[str.size()-1]-'a';
      G[a][b] = 1;
      deg[a] ++, deg[b] --;
      done[a] = done[b] = false;
    }
    
    dfs(a);
    
    //for(int i=0; i<26; i++) cout << done[i];
    //cout << endl;
    //for(int i=0; i<26; i++) cout << deg[i];
    bool flag = true;
    for(int i=0; i<26; i++) {
      if(!done[i]||deg[i]!=0) flag = false;
    }
    if(flag) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1196
n,c=map(int,input().split())
x=[]
v=[]
rightvalue=[]
temp=0
for i in range(n):
  xi,vi=map(int,input().split())
  x.append(xi)
  v.append(vi)
  temp+=vi
  rightvalue.append(temp-xi)
rightmaxdouble=[]
currentmax=0
for i in range(n):
  if currentmax<rightvalue[i]-x[i]:
    currentmax=rightvalue[i]-x[i]
  rightmaxdouble.append(currentmax)
leftvalue=[]
temp=0
for i in range(n):
  temp+=v[n-1-i]
  leftvalue.append(temp-(c-x[n-1-i]))
leftmaxdouble=[]
currentmax=0
for i in range(n):
  if currentmax<leftvalue[i]-(c-x[n-1-i]):
    currentmax=leftvalue[i]-(c-x[n-1-i])
  leftmaxdouble.append(currentmax)
ans=0
for i in range(n):
  if n-i>=2:
    if rightvalue[i]+leftmaxdouble[n-i-2]>ans:
      ans=rightvalue[i]+leftmaxdouble[n-i-2]
  else:
    if rightvalue[i]>ans:
      ans=rightvalue[i]
for i in range(n):
  if n-i>=2:
    if leftvalue[i]+rightmaxdouble[n-i-2]>ans:
      ans=leftvalue[i]+rightmaxdouble[n-i-2]
  else:
    if leftvalue[i]>ans:
      ans=leftvalue[i]
print(ans)

Measured memory_bytes: 24132
def count_up(numbers, i)
  calculated_results = numbers.map do |number|
    if (number % 2) == 0
      number / 2
    else
      return i
    end
  end
  i += 1
  count_up(calculated_results, i)
end

length = gets.to_i
numbers = gets.chomp.split(' ').map(&:to_i)
print count_up(numbers, 0)


Measured memory_bytes: 1788
H,W=map(int,input().split())
while H!=0 or W!=0:
    for b in range(H//2):
        for a in range(W//2):
            print("#.",end='')
        if W%2!=0:
            print("#",end='')
        print()    
        for a in range(W//2):
            print(".#",end='')
        if W%2!=0:
            print(".",end='')
        print()  
    if H%2!=0:
        for c in range(W//2):
            print("#.",end='')
        if W%2!=0:
            print("#",end='')
        print()  
    print()    
    H,W=map(int,input().split())    
else:
    pass


Measured memory_bytes: 6388
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

const int MOD = 1e9+7;

int pwr (int a, int b)
{
    if(b == 0)
        return 1;
    if(b & 1)
        return 1LL * a * pwr(a, (b ^ 1)) % MOD;
    int aux = pwr(a, (b >> 1));
    return 1LL * aux * aux % MOD;
}

int n, k;

int v[N_MAX];

bool cmp (const int &a, const int &b)
{
    return abs(a) > abs(b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    sort(v + 1, v + n + 1, cmp);
    int last1 = INT_MAX, last2 = INT_MAX;
    ll ans = 1;
    int cnt = 0;
    for(int i = 1; i <= k; i++)
    {
        int val = v[i];
        if(val < 0)
            val += MOD;
        ans = 1LL * ans * val % MOD;
        if(v[i] < 0)
            cnt++;
        if(v[i] < 0)
            last1 = v[i];
        if(v[i] > 0)
            last2 = v[i];
    }
    int first1 = INT_MAX, first2 = INT_MAX;
    for(int i = k + 1; i <= n; i++)
        if(v[i] > 0)
        {
            first1 = v[i];
            break;
        }
    for(int i = k + 1; i <= n; i++)
        if(v[i] < 0)
        {
            first2 = v[i];
            break;
        }
    if((cnt & 1))
    {
        ll ans1 = INT_MAX, ans2 = INT_MAX;
        if(last1 != INT_MAX && first1 != INT_MAX)
            ans1 = 1LL * ans * pwr(last1, MOD - 2) % MOD * first1 % MOD;
        if(last2 != INT_MAX && first2 != INT_MAX)
            ans2 = 1LL * ans * pwr(last2, MOD - 2) % MOD * first2 % MOD;
        if(ans1 == INT_MAX && ans2 == INT_MAX)
        {
            sort(v + 1, v + n + 1);
            ans = 1;
            for(int i = n; i >= n - k + 1; i--)
            {
                int val = v[i];
                if(val < 0)
                    val += MOD;
                ans = 1LL * ans * val % MOD;
            }
            cout << ans << "\n";
            return 0;
        }
        if(ans1 == INT_MAX)
            ans = ans2;
        else if(ans2 == INT_MAX)
            ans = ans1;
        else if(1LL * first1 * last2 > 1LL * first2 * last1)
            ans = ans1;
        else
            ans = ans2;
    }
    if(ans < 0)
        ans += MOD;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


const int MAX = 1000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



//-------------------------------------------------
// メモ
/*







*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y ;
  cin >> x >> y ;
  double a = (double)x/double(y) ; 
  if(a<0.5 ||a>2.0){
    cout << 0 <<endl ;
  }
  else if((x+y)%3!=0){
    cout << 0 <<endl ;
  }
  else{
    COMinit();
    cout << COM((x+y)/3, x-(x+y)/3) << endl;
  }
  
  
  
  return 0 ;
}



Measured memory_bytes: 23680
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<random>
#include<unordered_set>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e9-10;
const llint red=0xE869120;
const llint pro=1002001;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}

int main(void){
	int n,i;cin>>n;
	deque<int>a(n);
	deque<int>b;
	for(i=0;i<n;i++){cin>>a[i];}
	for(i=0;i<n;i++){
		if((n-i)%2==1){b.push_front(a[i]);}
		else{b.pub(a[i]);}
	}
	for(i=0;i<n;i++){
		cout<<b[i]<<" ";
	}cout<<endl;
	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  while (a > 0 && c > 0) {
    c -= b;
    a -= d;
  }

  if (c <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>


using namespace std;

int main()
{
  int n;
  string s, t;
  cin >> n;
  cin >> s;
  cin >> t;
  for( int i=0; i < n; ++i)
    cout << s[i] << t[i];

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#include <cmath>       //pow,logなど
#include <complex>     //複素数
#include <deque>       //両端アクセスのキュー
#include <functional>  //sortのgreater
#include <iomanip>     //setprecision(浮動小数点の出力の誤差)
#include <iostream>    //入出力
#include <iterator>    //集合演算(積集合,和集合,差集合など)
#include <map>         //map(辞書)
#include <numeric>     //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
#define int long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

signed main() {

    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int cnt = 0;

    if (a >= b) {
        while (a >= b) {
            b *= 2;
            cnt++;
        }
    }
    if (b >= c) {
        while (b >= c) {
            c *= 2;
            cnt++;
        }
    }
    if (cnt <= k) {
        print("Yes");
    } else {
        print("No");
    }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll INF = 1000000000000;

int main() {
	
	ll n, w, i, j, m = 0, mv = 0;
	cin >> n >> w;
	vll ws(n), vs(n);

	for (i = 0; i < n; i++) {
		cin >> ws[i] >> vs[i];
		m += vs[i];
	}

	vvll dp(n + 1, vll(m + 1, INF));

	for (i = 0; i <= n; i++) {
		dp[i][0] = 0;
		if (i > 0) {
			for (j = 1; j <= m; j++) {
				dp[i][j] = dp[i - 1][j];
				if (vs[i - 1] <= j)
					dp[i][j] = min(dp[i][j], dp[i - 1][j - vs[i - 1]] + ws[i - 1]);
				if (dp[i][j] <= w)
					mv = max(mv, j);
			}
		}
	}

	cout << mv << "\n";

	return 0;
}

Measured memory_bytes: 83160
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    ArrayList<Character> xl = new ArrayList<Character>();
    ArrayList<Character> yl = new ArrayList<Character>();
    ArrayList<Character> cl = new ArrayList<Character>();
    int max = 0;

    for (int i = 0; i < n; i++) {
      yl.add(s.charAt(i));
    }

    for (int i = 0; i < (n - 1); i++) {
      int cnt = 0;
      xl.add(s.charAt(i));
      yl.remove(0);
      cl.clear();

      for (char c : xl) {
        if (yl.contains(c) && !cl.contains(c)) {
          cnt++;
          cl.add(c);
        }
      }

      max = Math.max(cnt, max);
    }

    System.out.println(max);

  }
}

Measured memory_bytes: 36276
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
using namespace std;

map<int, int> m;

int n, a;


int main()
{
	cin >> n;
	while (n--) {
		cin >> a;
		if (m[a] > 0) {
			cout << "NO";
			return 0;
		}
		m[a] = 1;
	}
	cout << "YES";

	return 0;
}

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

int fanc(int N){
  int ans=1;
  for(int i=1;i<=N;i++) ans*=i;
  return ans;
}

int fanc2(int num[],int a){
  int cnt=0;
  for(int i=0;i<a;i++){
    if(num[a]>num[i]) cnt++;
  }
  return cnt;
}

int main() {
  int N,a=1,b=1,ans;
  cin>>N;
  int P[N],Q[N];
  for(int i=0;i<N;i++) cin>>P[i];
  for(int i=0;i<N;i++) cin>>Q[i];
  for(int i=0;i<N;i++){
    //cout<<"a:fanc2 is "<<fanc2(P,i)<<endl;
    a+=(P[i]-1-fanc2(P,i))*fanc(N-i-1);
    b+=(Q[i]-1-fanc2(Q,i))*fanc(N-i-1);
  }
  cout<<fabs(a-b)<<endl;
}	


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  double xyz = (double) l / 3;
  double res = xyz * xyz * xyz;
  cout << fixed << setprecision(10) << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, int>;

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

    s64 n;
    cin >> n;
    vector<P> a(n);
    rep (i, n)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end(), greater<P>());
    s64 dp[n + 1][n + 1];
    rep (i, n + 1) rep (j, n + 1) dp[i][j] = 0;

    s64 ans = 0;
    rep (l, n)
    {
        for (int r = 0; l + r <= n; ++r)
        {
            if (l + r == n)
            {
                ans = MAX(ans, dp[l][r]);
                break;
            }
            else
            {
                int pos = a[l + r].second;
                s64 A = a[l + r].first;
                dp[l + 1][r] = MAX(dp[l + 1][r], dp[l][r] + A * abs(pos - l));
                dp[l][r + 1] = MAX(dp[l][r + 1], dp[l][r] + A * abs(n - 1 - r - pos));
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 34960
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.printf("%d %d\n", a * b , 2 * (a + b) );
	}
}

Measured memory_bytes: 17168
#include <iostream>
#include <vector>

using namespace std;
int dx[] = {-1,  0, 0, 1};
int dy[] = { 0, -1, 1, 0};
int w, h;
vector< vector<char> > Field;
vector< vector<char> > used;
bool Bflag;
bool Wflag;
int Bsum;
int Wsum;

void search(int x, int y)
{
	used[y][x] = true;
	if(Bflag && Wflag)
	{
		return;
	}
	for(int i = 0; i < 4; ++i)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(Field[ny][nx] == '.' && !used[ny][nx])
		{
			search(nx, ny);
		}
		else if(Field[ny][nx] == 'W')
		{
			Wflag = true;
		}
		else if(Field[ny][nx] == 'B')
		{
			Bflag = true;
		}
	}
}

void sum(int a, int b, char c)
{
	Field[b][a] = '2';
	if(c == 'B')
	{
		++Bsum;
		for(int i = 0; i < 4; ++i)
		{
			int nx = a + dx[i];
			int ny = b + dy[i];
			if(Field[ny][nx] == '.')
			{
				sum(nx, ny, c);
			}
		}		
	}
	else if(c == 'W')
	{
		++Wsum;
		for(int i = 0; i < 4; ++i)
		{
			int nx = a + dx[i];
			int ny = b + dy[i];
			if(Field[ny][nx] == '.')
			{
				sum(nx, ny, c);
			}
		}
	}
}

void invalid(int a, int b, char c)
{
	Field[b][a] = c;
	for(int i = 0; i < 4; ++i)
	{
		int nx = a + dx[i];
		int ny = b + dy[i];
		if(Field[ny][nx] == '.')
		{
			invalid(nx, ny, c);
		}
	}
}

void solve()
{
	while(cin >> w >> h, w || h)
	{
		Field.resize(h + 2);
		used.resize(h + 2);
		for(int i = 0; i <= h + 1; ++i)
		{
			Field[i].resize(w + 2);
			used[i].resize(w + 2);
		}
		for(int i = 0; i <= h + 1; ++i)
		{
			for(int j = 0; j <=  w + 1; ++j)
			{
				Field[i][j] = '2';
				used[i][j] = false;
			}
		}
		for(int i = 1; i <= h; ++i)
		{
			for(int j = 1; j <= w; ++j)
			{
				cin >> Field[i][j];
			}
		}
		Bsum = 0;
		Wsum = 0;
		for(int i = 1; i <= h; ++i)
		{
			for(int j = 1; j <= w; ++j)
			{
				Bflag = false;
				Wflag = false;
				if(Field[i][j] == '.')
				{
					search(j, i);
					if(Bflag && !Wflag)
					{
						sum(j, i, 'B');
					}
					else if(!Bflag && Wflag)
					{
						sum(j, i, 'W');
					}
					else if(Bflag && Wflag)
					{
						invalid(j, i, '2');
					}
				}
			}
		}
		cout << Bsum << " " << Wsum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX+1],dp2[MAX+2];

int main() {
    for(int i = 1;i <= MAX;i++) {
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for(int n = 1;n * (n + 1) * (n + 2) / 6 <= MAX;n++) {
        int a = n * (n + 1) * (n + 2) / 6;
        for(int i = a;i <= MAX;i++) {
            dp1[i] = min(dp1[i],dp1[i - a] + 1);
        }
        if(a % 2 == 0)continue;
        for(int i = a;i <= MAX;i++) {
            dp2[i] = min(dp2[i],dp2[i - a] + 1);
        }
    }

    while(true) {
        int n;
        cin >> n;
        if(n == 0)break;
        cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 10912
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

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

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,d;
	cin>>n>>d;

	int cnt=0;

	for(i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;

		long double  dist=sqrtl(a*a+b*b);
		if(dist<=d)
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;

}

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

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long n = 0;
    cin >> n;

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

    map<long long, set<long long>> m, p;
    for (long long i = 1; i <= n; i++)
    {
        set<long long> s;
        m[i - a[i]] = s;
        p[i + a[i]] = s;
    }
    for (long long i = 1; i <= n; i++)
    {
        m[i - a[i]].insert(i);
        p[i + a[i]].insert(i);
    }

    // cout << "m: ";
    // for (auto &e : m)
    // {
    //     cout << e.first << ":" << e.second.size() << ", ";
    // }
    // cout << endl;

    // cout << "p: ";
    // for (auto &e : p)
    // {
    //     cout << e.first << ":" << e.second.size() << ", ";
    // }
    // cout << endl;

    long long cnt = 0;
    for (auto &e : p)
    {
        auto it = m.find(e.first);
        if (it != m.end())
        {
            // cout << (*it).second.size() << " " << e.second.size() << endl;
            cnt += (*it).second.size() * e.second.size();
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 58352
import sys

def solve(s: str, t: str):
    ls=len(s)
    lt=len(t)
    dp=[[0]*(lt+1) for _ in range(ls+1)] # dp[0:ls+1][0:lt+1]

    for i in range(ls):
        for j in range(lt):
            if s[i]==t[j]:
                dp[i+1][j+1]=dp[i][j]+1
            if dp[i+1][j]>dp[i+1][j+1]: dp[i+1][j+1]=dp[i+1][j]
            if dp[i][j+1]>dp[i+1][j+1]: dp[i+1][j+1]=dp[i][j+1]

    ans=""
    while ls>0 and lt>0:
        if dp[ls][lt]==dp[ls-1][lt]:
            ls-=1
        elif dp[ls][lt]==dp[ls][lt-1]:
            lt-=1
        else:
            ans=s[ls-1]+ans
            ls-=1
            lt-=1

    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 112732
def revert_cipher(str, a, b)
  a %= 26
  new = Array.new
  ary = str.unpack("c*")
  ary.each {|c|
    if c == 0x20 then
      new.push(c)
      next
    end
    i = c - 0x61
    i -= b
    while (i < 0) do i += 26 end
    found = true
    26.times {|n|
      break if i % a == 0
      found = false if n == 25
      i += 26
    }
    return "" if not found
    i /= a
    i += 0x61
    new.push(i)
  }
  return new.pack("c*")
end

# that -> +19 +7 +0 +19
# i1 = (19 * a + b) mod 26
# i2 = (7 * a + b)  mod 26
# i3 = b
#
# i1 = (19 * a + i3) mod 26
# 19 * a = i1 * 26 * n - i3
# i1 * 26 * n - i3 が19の倍数になる時の値がa
def find_that(str)
  ary = str.unpack("c*")
  pos = 0
  i_ary = Array.new
  ary.each { |c|
    if (c == 0x20) then
      pos = 0
      next
    end
    next if pos >= 4 # 4文字以上の領域はスキップする
    i_ary[pos] = c - 0x61
    pos += 1
    if (pos == 4) then
      next if i_ary[0] != i_ary[3]
      a19 = i_ary[0] - i_ary[2]
      while (a19 < 0) do a19 += 26 end
      found = true
      26.times {|i|
          break if a19 % 19 == 0
          found = false if i == 25
          a19 += 26
      }
      next if not found
      a = a19 / 19
      next if i_ary[1] != (a * 7 + i_ary[2]) % 26
      return [a, i_ary[2]]
    end
  }
  return []
end

# this -> +19 +7 +8 +18
# i1 = (19 * a + b) mod 26
# i2 = (7 * a + b) mod 26
# i3 = (8 * a + b) mod 26
# i4 = (18 * a + b) mod 26
#  i1 - i4 = (19a + b) - (18a +b)
#  i1 - i4 = a
def find_this(str)
  ary = str.unpack("c*")
  pos = 0
  i_ary = Array.new
  ary.each { |c|
    if (c == 0x20) then
      pos = 0
      next
    end
    next if pos >= 4 # 4文字以上の領域はスキップする
    i_ary[pos] = c - 0x61
    pos += 1
    if (pos == 4) then
      i1 = i_ary[0]
      i3 = i_ary[2]
      i1 += 26 if i_ary[0] < i_ary[3]
      i1i4 = i1 - i_ary[3]
      i3 += 26 if i_ary[2] < i_ary[1]
      i3i2 = i3 - i_ary[1]
      next if i1i4 != i3i2
      b = i_ary[1] - i1i4 * 7
      while (b < 0) do b += 26 end
      next if i_ary[0] != (i1i4 * 19 + b) % 26
      next if i_ary[2] != (i1i4 * 8 + b) % 26
      next if i_ary[3] != (i1i4 * 18 + b) % 26
      return [i1i4, b]
    end
  }
  return []
end

lines = STDIN.gets.chomp
lines.to_i.times {|i|
  str = STDIN.gets.chomp
  ab = find_that(str)
  ab = find_this(str) if ab.empty?
  puts revert_cipher(str, ab[0], ab[1]) if not ab.empty?
}

Measured memory_bytes: 6084
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	ans=n%1000;
	cout<<(ans==0?0:1000-ans)<<endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<iostream>

using namespace std;

int main(){
    int q,a,b,c,d;
    // scanf("%d", &q);
    cin >> q;
    for(int i=0;i<q;i++){
        // scanf("%d %d %d %d", &a, &b, &c, &d);
        cin >> a >> b >> c >> d;
        int n = a+b, aa, bb, l = max((a+b) / (b+1), (b+a) / (a+1));

        int ok = 0, ng = a+b+1;
        while(ng-ok > 1){
            int mid = (ok+ng)/2;
            aa = a - mid/(l+1)*l - mid%(l+1);
            bb = b - mid/(l+1);
            
            if((long long)bb < (long long)(aa+1)*(long long)l){
                ok = mid;
            }else{
                ng = mid;
            }
        }

        string ans = "";
        if(c <= ok){
            for(int j=c-1;j<min(d,ok);j++){
                // putchar((j % (l+1) == l)?'B':'A');
                ans += (j % (l+1) == l)?'B':'A';
            }
        }
        if(ng <= d){
            for(int j=max(ok,c-1);j<min(n,d);j++){
                // putchar(((n-j) % (l+1) == 0)?'A':'B');
                ans += ((n-j) % (l+1) == 0)?'A':'B';
            }
        }
        cout << ans << endl;
        // puts("");
    }
}


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

int main(){
    string s;
    int A, Z;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A'){
            A = i;
            break;
        }
    }
    for(int i=s.size()-1; i>0; i--){
        if(s[i] == 'Z'){
            Z = i;
            break;
        }
    }
    cout << Z-A+1 << endl;
}

Measured memory_bytes: 640