akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
 string S;
 char c;
 int n;
 cin >> S;

 n=15-S.length();

 for(c : S){
  if(c=='o'){
   n++;
 }
}

 if(n>=8){
  cout << "YES" << endl;
}else{
 cout << "NO" << endl;
}
 
return 0;
}

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

const double PI = acos(-1);
int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    //角度を求める
    double th = double(h * 60 + m) / 720 * 2 * PI;//時針
    double tm = double(m)/60 * 2 * PI;//分針
    //座標を求める
    double xh = a*cos(th);
    double yh = a*sin(th);
    double xm = b*cos(tm);
    double ym = b*sin(tm);

    //座標の差
    double dx = xh - xm, dy = yh - ym;

    double ans = sqrt(dx*dx + dy*dy);
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    unsigned int long long A;
    long double B;
    cin >> A >> B;
    //int C = B * 100;
   // C/=100;
    cout << std::fixed << std::setprecision(0) << floor((A*B) )<< endl;
    return 0;
}


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

const int Maxn = 200005;
int n, dep[Maxn];
vector <int> g[Maxn];
void dfs(int u, int par = 0) {
  dep[u] = dep[par] + 1;
  for (auto &v: g[u])
    if (v != par) dfs(v, u);
}
int main(int argc, const char *argv[]) {
  ios_base :: sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(12);
  cin >> n, dep[0] = -1;
  for (int i = 1; i < n; ++ i) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  dfs(max_element(dep + 1, dep + n + 1) - dep);
  int cnt = *max_element(dep + 1, dep + n + 1);
  if (cnt % 3 == 1) cout << "Second\n";
  else cout << "First\n";
}

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

int main(){
  int n,m ;
  cin >> n >> m ;
  vector<vector<int>> s(m,vector<int>(10,-1)) ;
  for(int i=0;i<m;i++){
    int x ; cin >> x ;
    for(int k=0;k<x;k++) cin >> s.at(i).at(k) ; 
  }
  vector<int> p(m) ;
  for(int i=0;i<m;i++) cin >> p.at(i) ;
  bool ok = true ;
  int ans = 0 ;
  for(int tmp=0;tmp<(1<<n);tmp++){
    bitset<10> b(tmp) ;
    ok = true ;
    for(int i=0;i<m;i++){
      int cnt = 0 ;
      for(int j=0;j<10;j++){
        if(s.at(i).at(j)==-1) break ;
        if(b.test(s.at(i).at(j)-1)) cnt++ ;
      }
      if(!(cnt%2==p.at(i))){
        ok = false ;
        break ;
      }
    }
    if(ok) ans++ ;
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[] B;
	static boolean[][] g;
	static boolean[] used;
	static HashMap<Long, Integer> memo;
	static long[] mask;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			Country[] cs = new Country[N];
			used = new boolean[N];
			B = new int[N];
			for (int i = 0; i < N; ++i) {
				cs[i] = new Country();
				B[i] = cs[i].b;
			}
			used[0] = true;
			g = new boolean[N][N];
			for (int i = 0; i < N; ++i) {
				for (String o : cs[i].c) {
					for (int j = 0; j < N; ++j) {
						if (o.equals(cs[j].a)) {
							g[i][j] = true;
							if (i == 0) used[j] = true;
							break;
						}
					}
				}
			}
			int ans = B[0];
			for (int i = 0; i < N; ++i) {
				if (!used[i]) ans += solve(i);
			}
			System.out.println(ans);
		}
	}

	static int solve(int cur) {
		int pos = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(cur);
		used[cur] = true;
		while (pos < list.size()) {
			int c = list.get(pos++);
			for (int i = 0; i < N; ++i) {
				if (g[c][i] && !used[i]) {
					used[i] = true;
					list.add(i);
				}
			}
		}
		mask = new long[list.size()];
		for (int i = 0; i < list.size(); ++i) {
			for (int j = 0; j < list.size(); ++j) {
				if (g[list.get(i)][list.get(j)]) {
					mask[i] |= 1L << list.get(j);
				}
			}
			mask[i] |= 1L << list.get(i);
		}
		memo = new HashMap<Long, Integer>();
		return dfs(0, list, 0);
	}

	static int dfs(int pos, ArrayList<Integer> list, long st) {
		if (pos == list.size()) return 0;
		if (pos > 20 && memo.containsKey(((long) pos << 50) | st)) {
			return memo.get(((long) pos << 50) | st);
		}
		int cur = list.get(pos);

		// not use cur
		int ret = dfs(pos + 1, list, st | (1L << cur));

		// use cur
		if ((st & (1L << cur)) == 0) {
			int sum = B[cur];
			sum += dfs(pos + 1, list, st | mask[pos]);
			ret = Math.max(ret, sum);
		}

		if (pos > 20) {
			memo.put(((long) pos << 50) | st, ret);
		}
		return ret;
	}

	static class Country {
		String a;
		int b;
		String[] c;

		Country() {
			a = sc.next();
			b = sc.nextInt();
			int cc = sc.nextInt();
			c = new String[cc];
			for (int i = 0; i < cc; ++i) {
				c[i] = sc.next();
			}
		}
	}
}

Measured memory_bytes: 191396
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    T = list(str(input().strip()))
    S = [int(t) if t != '?' else -1 for t in T]
    n = len(S)

    dp = [[0] * 13 for _ in range(n)]
    s = S.pop()
    if s < 0:
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][s] = 1

    digit = 1
    m = 1
    while S:
        s = S.pop()
        m = (m * 10) % 13
        if s < 0:
            for k in range(10):
                M = (m * k) % 13
                for i in range(13):
                    j = (i + M) % 13
                    dp[digit][j] += dp[digit-1][i]
                    dp[digit][j] %= MOD
        else:
            M = (m * s) % 13
            for i in range(13):
                j = (i + M) % 13
                dp[digit][j] += dp[digit-1][i]
                dp[digit][j] %= MOD
        digit += 1

    return dp[n-1][5]


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 68216
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

int calc(int m, vi & add) {
  int cnt = 0;
  for (int a : add) {
    cnt += m / a;
    m %= a;
  }
  return cnt;
}

int main() {
  int n;
  scanf("%d", &n);
  vi add6 = {1};
  while (true) {
    int nx = add6.back() * 6;
    if (nx > n) {
      break;
    } else {
      add6.push_back(nx);
    }
  }
  reverse(all(add6));
  vi add9 = {1};
  while (true) {
    int nx = add9.back() * 9;
    if (nx > n) {
      break;
    } else {
      add9.push_back(nx);
    }
  }
  reverse(all(add9));

  int ans = INT_MAX/2;
  rep (i, n+1) {
    int j = n - i;
    ans = min(ans, calc(i, add6) + calc(j, add9));
  }

  printf("%d\n", ans);

  return 0;
}


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

#define X first
#define Y second
#define Mod 1000000007
#define N 2010
typedef long long ll;
typedef pair<int,int> pii;

char s[N][N];
int blue[N][N], row[N][N], col[N][N];

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n, m, Q;
	scanf("%d %d %d", &n, &m, &Q);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			blue[i][j] = blue[i - 1][j] + blue[i][j - 1] - blue[i - 1][j - 1] + (s[i][j] == '1');
			row[i][j] = row[i - 1][j] + row[i][j - 1] - row[i - 1][j - 1];
			col[i][j] = col[i - 1][j] + col[i][j - 1] - col[i - 1][j - 1];
			if (s[i][j] == '1' && s[i][j - 1] == '1') ++row[i][j];
			if (s[i][j] == '1' && s[i - 1][j] == '1') ++col[i][j];
		}
	}
	
	
	while (Q--)
	{
		int x1, y1, x2, y2, res = 0;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		res = blue[x2][y2] - blue[x1 - 1][y2] - blue[x2][y1 - 1] + blue[x1 - 1][y1 - 1];
		res -= row[x2][y2] - row[x2][y1] - row[x1 - 1][y2] + row[x1 - 1][y1];
		res -= col[x2][y2] - col[x1][y2] - col[x2][y1 - 1] + col[x1][y1 - 1];
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 53120
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define vs v.size()
using namespace std;

int main() {
   ll k,a,b;
   cin>>k>>a>>b;
   ll flag =0;
   for(ll i=a;i<=b;i++){
       if(i%k == 0){
           flag = 1;
           break;
       }
   }
   if(flag == 1)
       cout<<"OK\n";
   else
       cout<<"NG\n";
}

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

const double PI = 3.14159265358979323846;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int N,M;
  cin >> N >> M;
  vector<set<int>> routes(N+1);
  for(int i=1; i<M+1; i++){
    int from, to;
    cin >> from >> to;
    routes[from].insert(to);
    routes[to].insert(from);
  }
  // 次に調べる起点
  queue<int> sp_que;
  vector<int> min_steps(N+1,-1);
  min_steps[1] = 1;
  sp_que.push(1);
  vector<int> from_room(N+1);
  while(!sp_que.empty()){
    int current_room = sp_que.front();
    sp_que.pop();
    int step = min_steps[current_room];
    set<int> route_set = routes[current_room];
    for(int try_room : route_set){
      if(min_steps[try_room] == -1 || min_steps[try_room] > step+1){
        min_steps[try_room] = step+1;
        from_room[try_room] = current_room;
        sp_que.push(try_room);
      }
    }
  }
  cout << "Yes" << endl;
  for(int i=2;i<N+1;i++){
    cout << from_room[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 32324
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    rep(i,n-k,n-1)ans+=a[i];
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n = 3;
    int a[3][3];
    bool f[3][3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            f[i][j] = false;
        }
    }
    int q;cin >> q;
    while(q--){
        int b;cin >> b;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(a[i][j] == b) f[i][j] = true;
            }
        }
    }
    bool ans = false;
    for (int i = 0; i < n; i++) {
        if(f[i][0]&&f[i][1]&&f[i][2]) ans = true;
        if(f[0][i]&&f[1][i]&&f[2][i]) ans = true;
        if(f[0][0]&&f[1][1]&&f[2][2]) ans = true;
        if(f[0][2]&&f[1][1]&&f[2][0]) ans = true;
    }
    if(ans) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    d = [[None]*51 for _ in [0]*51]  # 目的のあまり、現在の数値
    for i in range(51):
        d[i][i] = [[]]
    for i in range(51):  # あまり
        for j in range(i+1, 51):  # 現在の数値
            temp = []
            for kk in range(1, j+1):  # 割る数
                k = j % kk
                if d[i][k] is None:
                    continue
                for l in d[i][k]:
                    temp += [l+[kk]]
            if temp == []:
                temp = None
            d[i][j] = temp
    c = [d[bb][aa] for aa, bb in zip(a, b)]
    if None in c:
        print(-1)
        return
    ans = 0
    while True:
        M = -1
        for i in range(n):
            if [] in c[i]:
                c[i] = [[]]
            else:
                m = min([j[-1] for j in c[i]])
                M = max(M, m)
        if M == -1:
            break
        ans += 2**M
        for i in range(n):
            temp = []
            if c[i] == [[]]:
                continue
            for j in c[i]:
                if j[-1] == M:
                    temp.append(j[:-1])
                elif j[-1] < M:
                    temp.append(j)
            c[i] = temp
    print(ans)


main()


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

class Atcoder104
{
    public static void Main()
    {
        string[] length = Console.ReadLine().Split(' ');
        int[] l = length.Select(s => int.Parse(s)).ToArray();

        int a = l.Min();
        var List = new List<int>();

        List.AddRange(l);
        List.Remove(a);

        int b = List.Min();

        Console.WriteLine(a * b / 2);
    }
}

Measured memory_bytes: 13396
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
)
 

func main(){
  a := float64(0)
  fmt.Scan(&a)
  pi := 3.14159265359
  //fmt.Println(a*a*pi,a*2*pi)
  fmt.Printf("%f %f\n",a*a*pi,a*2*pi)
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


Measured memory_bytes: 1192
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int k, n;
    cin >> k >> n;

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

    int mx = a[0] + (k - a[n - 1]);
    for (int i = 0; i < n - 1; i++) {
        mx = max(mx, a[i + 1] - a[i]);
    }

    cout << k - mx << "\n";
    return 0;
}

Measured memory_bytes: 1656
(defn split-space [s]
  (map #(Long/parseLong %) (.split s " ")))

(defn read-n [n]
  (for [i (range n)] (split-space (read-line))))

(defn square [x]
  (* x x))

(defn distance [d [xi yi] xs]
  (if (zero? (count xs))
    d
    (recur (reduce (fn [acc [xj yj]]
                     (+ acc (Math/sqrt (+ (square (- xi xj))
                                          (square (- yi yj)))))) d xs)
           (first xs)
           (rest xs))))

(defn average-length []
  (->>
   (Long/parseLong (read-line))
   ((fn [n]
      (->>
       (read-n n)
       ((fn [xs] (distance 0 (first xs) (rest xs))))
       ((fn [s] (/ (* 2 s) n))))))))

(println (average-length))

Measured memory_bytes: 68428
A, B, C, D, E, F = map(int, input().split())

water_masses = set()
for i in range(31):
    for j in range(31):
        mass = 100 * A * i + 100 * B * j
        if 0 < mass and mass <= F:
            water_masses.add(mass)

sugar_masses = set()
for i in range(3000 // C + C):
    for j in range(3000 // D + D):
        mass = C * i + D * j
        if mass <= F:
            sugar_masses.add(mass)

res_water = 100 * A
res_sugar = 0
for m_water in water_masses:
    for m_sugar in sugar_masses:
        if m_water + m_sugar > F:
            continue

        con = m_sugar / (m_water + m_sugar)
        if con <= (E / (100 + E)) and con > (res_sugar / (res_water + res_sugar)):
            res_water = m_water
            res_sugar = m_sugar


print(res_water + res_sugar, res_sugar)


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
static const int MAX_N = 100000;
static const int inf  = 1ll<<60;
static const int MAX_SEG=1<<17;
typedef pair<int,int> pii;

class segment{
public:
    int n;
    int dat[MAX_SEG*2];
    void init(int n_){
        for(int i=0;i<2*MAX_SEG-1;++i)dat[i]=0;

    }
    void update(int a,int b,int x,int k=0,int l=0,int r=MAX_SEG){
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            dat[k]=max(dat[k],x);
            return;
        }
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
    }
    int query(int k){
        k+=MAX_SEG-1;
        int ret=dat[k];
        while(k){
            k=(k-1)/2;
            ret=max(ret,dat[k]);
        }
        return ret;
    }
};

int N,M;
vector<int> g[MAX_N+5];
int depth[MAX_N+5];
int par[20][MAX_N];
int tin[2*MAX_N+5],tout[2*MAX_N+5];
int k=0;

void dfs(int v,int p,int d){
    par[0][v]=p;
    depth[v]=d;
    tin[v]=k++;
    for(int u=0;u<g[v].size();++u)dfs(g[v][u],v,d+1);
    tout[v]=k;
}
void fill_table(){
    for(int i=0;i<19;i++){
        for(int j=0;j<N;j++){
            if(par[i][j]==-1)par[i+1][j]=-1;
            else par[i+1][j]=par[i][par[i][j]];
        }
    }
}

signed main(){
    while(1){
        int ans=0;
        cin>>N>>M;
        if(N==0&&M==0)break;
        for(int i=0;i<N;++i)g[i].clear();
        memset(par,0,sizeof(par));
        for(int i=1;i<N;++i){
            int p;
            cin>>p;
            p--;
            g[p].PB(i);
        }
        k=0;
        dfs(0,-1,0);
        fill_table();
        segment seg;
        seg.init(N);
        for(int t=0;t<M;++t){
            char que;
            int v;
            cin>>que;
            cin>>v;
            v--;
            if(que=='M'){
                seg.update(tin[v],tout[v],depth[v]);
            }
            else{
                int q=seg.query(tin[v]);
                for(int i=19;i>=0;--i){
                    if((depth[v]-q)>>i&1)v=par[i][v];
                }
                ans+=v+1;
            }
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;

int main()
{
  string S;
  while(cin >> S, S != "#") {
    char mas[10][10];
    fill(mas[0], mas[10], '.');
    int w = 0, h = 0, mw = 0;
    for(int i = 0; i < S.size(); i++) {
      mw = max(w, mw);
      if(S[i] == '/') w = 0, h++;
      else if(S[i] == 'b') mas[h][w++] = 'b';
      else w += S[i]-'0';
    }
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b, --c, --d;
    swap(mas[a][b], mas[c][d]);
    string ans = "";
    for(int i = 0; i <= h; i++) {
      int cnt = 0;
      for(int j = 0; j < mw; j++) {
	if(mas[i][j] == 'b') {
	  if(cnt) ans += (char)(cnt+'0');
	  ans += 'b', cnt = 0;
	}
	else cnt++;
	//putchar(mas[i][j]);
      }
      if(cnt) ans += (char)(cnt+'0');
      if(i != h) ans += '/';
      //puts("");
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool can_talk = false;
	if(abs(a - c) <= d){
		can_talk = true;
	}else if(abs(a - b) <= d && abs(b - c) <= d){
		can_talk = true;
	}
	if(can_talk) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
//34
#include<iostream>
#include<algorithm>

using namespace std;

void con(bool *i,bool (*f)[501],int n,int r){
  i[n]=true;
  if(r){
    for(int j=1;j<501;j++){
      if(f[n][j]){
	con(i,f,j,r-1);
      }
    }
  }
}

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    bool f[501][501]={{}};
    while(m--){
      int a,b;
      cin>>a>>b;
      f[a][b]=f[b][a]=true;
    }
    bool inv[501]={};
    con(inv,f,1,2);
    cout<<count(inv+2,inv+n+1,true)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main()
{
	char a[4];
	int num[4],i;
	scanf("%s",a);
	for(i=0;i<4;i++)
	{
		num[i]=a[i]-'0';
	}
	if(num[0]+num[1]+num[2]+num[3]==7)
	{
		printf("%d+%d+%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]+num[2]+num[3]==7)
	{
		printf("%d-%d+%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]+num[3]==7)
	{
		printf("%d-%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]+num[3]==7)
	{
		printf("%d-%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]-num[2]-num[3]==7)
	{
		printf("%d-%d-%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]-num[1]+num[2]-num[3]==7)
	{
		printf("%d-%d+%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]-num[2]+num[3]==7)
	{
		printf("%d+%d-%d+%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]+num[2]-num[3]==7)
	{
		printf("%d+%d+%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
	else if(num[0]+num[1]-num[2]-num[3]==7)
	{
		printf("%d+%d-%d-%d=7\n",num[0],num[1],num[2],num[3]);
	}
}


Measured memory_bytes: 128
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;

int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int dp[353][353]={0};
int bow[353][353]={0};

set<string> a;

int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		int l=0,d=0,m=0;
		int wl=0,wd=0,wm=0;
		rep(i,n){
		int a,b,c;
		scanf("%d%*c%d%d",&a,&b,&c);
			if(b>=45&&c<=15)
				c+=60;
			if(a>=0&&a<=1||a>=21&&a<=23){
				wm++;
				if(c-b<=8)
					m++;
				
			}
			else if(a>=18&&a<=20){
				wd++;
				if(c-b<=8)
					d++;
			}
			else if(a>=11&a<=14){
				wl++;
				if(c-b<=8)
					l++;
			}
		}
		if(wl<=0)
			cout<<"lunch no guest"<<endl;
		else
			cout<<"lunch "<<l*100/wl<<endl;
		if(wd<=0)
			cout<<"dinner no guest"<<endl;
		else
			cout<<"dinner "<<d*100/wd<<endl;
		if(wm<=0)
			cout<<"midnight no guest"<<endl;
		else
			cout<<"midnight "<<m*100/wm<<endl;
		
	}
}

Measured memory_bytes: 1248
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]a=new int[n];
		Arrays.setAll(a,i->s.nextInt());

		long r=0;
		for(int i=0;i<n;++i)
			for(int j=i+1;j<n;++j)
				r+=a[i]*a[j];
		System.out.println(r);
	}
}


Measured memory_bytes: 27348
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let s = input_line_str().to_charvec();
    if n % 2 != 0 {
        p("No");
        return;
    }
    let mut i = 0;
    while i + n / 2 < n {
        if s[i] != s[i + n / 2] {
            p("No");
            return;
        }
        i += 1;
    }
    p("Yes");
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<int> A;
vector<int> X;

int main(void) {
    cin>>N;

    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;
        A.push_back(a);
        X.push_back(a);
    }

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

    for(int i = 0;i < N;i++) {
        if(A[i] == X[N-1]) {
            cout<<X[N-2]<<endl;
        } else {
            cout<<X[N-1]<<endl;
        }
    }

    return 0;
}





Measured memory_bytes: 3436
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int d[90001];
int px[90001], py[90001];

int main(){

  int H, W, D;
  cin >> H >> W >> D;

  int a;

  REP(i, H){
    REP(j, W){
      cin >> a;
      px[a] = i;
      py[a] = j;
    }
  }

  FOR(i, D+1, H*W+1, 1){
    d[i] = d[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D]);
  }

  int Q;
  cin >> Q;

  int L, R;
  while(Q--){
    
    cin >> L >> R;
    cout << d[R]-d[L] << endl;

  }

  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

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


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A, B;

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

    std::cin >> A >> B;

    int mx = std::max({A + B, A - B, A * B});
    std::cout << mx << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  LL N, M;
  cin >> N >> M;
  if(N==1&&M==1) cout << 1 << endl;
  else if(N==1) cout << M-2 << endl;
  else if(M==1) cout << N-2 << endl;
  else cout << (N-2)*(M-2) << endl;

  return 0;
}


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

int main()
{
    int c[3][3];
    int a[3];
    int b[3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    for (int n  = 0; n <= 100; n++) {
        a[0] = n;
        b[0] = c[0][0] - a[0];
        b[1] = c[1][0] - a[0];
        b[2] = c[2][0] - a[0];
        if (c[0][1] < b[0] || c[0][2] < b[0]) {
            continue;
        }
        a[1] = c[0][1] - b[0];
        a[2] = c[0][2] - b[0];
        if (b[1] + a[1] == c[1][1] && b[2] + a[1] == c[2][1] && b[1] + a[2] == c[1][2] && b[2] + a[2] == c[2][2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int n;
int dp[101][4][4][4];
// 0 A 1 C 2 G 3 T
int go(int i,int pre1,int pre2,int pre3)
{
   if(i>=n){
            if(pre2==0 && pre1==2 && pre3==1)
               return 0;
            else if(pre1==0 && pre2==2 && pre3==1)
               return 0;
            else if(pre1==0 && pre2==1 && pre3==2)
                return 0; 
              return 1;
   }
   if(dp[i][pre1][pre2][pre3]!=-1)
    return dp[i][pre1][pre2][pre3];
   else
     {  int ans=0;
        for(int j=0;j<4;j++) 
        {   if(pre2==0 && pre1==2 && pre3==1)
               continue;
            if(pre1==0 && pre2==2 && pre3==1)
               continue;
            if(pre1==0 && pre2==1 && pre3==2)
                continue;
            if(pre1==0 && pre2==2 && j==1)
                continue;
            if(pre3==0 && pre2==2 && j==1)
               continue;
            if(pre2==0 && pre3==2 && j==1)
               continue;
            if(pre2==0 && pre3==1 && j==2)
                continue;
            if(pre1==0 && pre3==2 && j==1)
               continue;      
            ans=(ans+go(i+1,pre2,pre3,j))%1000000007;
        }
        dp[i][pre1][pre2][pre3]=ans;
       return ans; 
     }  
}

int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){  
    cin>>n;
    int ans=0;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<4;i++)
       {
         for(int j=0;j<4;j++)
           {for(int k=0;k<4;k++)
                    ans=(ans+go(3,i,j,k))%1000000007;}
       }
     //cout<<dp[4]  
    cout<<ans<<" ";
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n;
int a[2005];
int gcd(int a, int b){
    return a == 0 ? b:gcd(b%a,a);
}
int vis[2005];
int nxt[2005];
vector<int> dfs(int u){
    vector<vector<int> > pos;
    for (int i = 1; i <= n; i++){
        if ((a[i] == 1 || gcd(a[u],a[i]) != 1) && vis[i] == 0){
            //printf("%d -> %d: gcd(%d,%d) is %d\n",u,i,a[i],a[u],gcd(a[i],a[u]));
            vis[i] = 1;
            pos.push_back(dfs(i));
        }
    }
    int NUM = pos.size();
    int ct[NUM];
    memset(ct,0,sizeof(ct));
    priority_queue<ii> pq;
    for (int i = 0; i < NUM; i++){
        pq.push({pos[i][0],i});
    }
    vector<int> ans;
    if (u != 0) ans.push_back(a[u]);
    while (pq.size()){
        ii cur = pq.top(); pq.pop();
        ans.push_back(cur.first);
        int id = cur.second;
        ct[id]++;
        if (ct[id] != pos[id].size()){
            pq.push({pos[id][ct[id]],id});
        }
    }
    return ans;
}
int main(){
    scanf("%d",&n);
    for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    vector<int> v = dfs(0);
    for (auto x : v){
        printf("%d ",x);
    }

}


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

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

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

	vector<int> b( N+1 );
	vector<int> result;

	for( int i = N; i >= 1; --i ) {
		int x = 0;

		for( int j = i+i; j <= N; j += i ) {
			x += b[j];
		}

		if( (x & 1) != a.at(i) ) {
			b.at( i ) = 1;
			result.push_back( i );
		}
	}

	cout << result.size() << endl;

	for( int i = 0; i < result.size(); ++i ) {
		cout << result.at( i );

		if( i < result.size()-1 ) {
			cout << " ";
		}
	}

	cout << endl;
}


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;

int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
	else {
		ll ans = min(a * b, min(b * c, a * c));
		cout << ans << endl;
	}
	return 0;
}



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

int main(void)
{
	int n, v, j;
	cin >> n;
	vector<int>A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i];
	for (int i = 0; i < n; i++) {
		cout << A[i];
		if (i != n - 1)
			cout << " ";
		else
			cout << endl;
	}

	for (int i = 1; i < n; i++)
	{
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (int k = 0; k < n; k++) {
			cout << A[k];
			if (k != n - 1)
				cout << " ";
			else
				cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3100
public class Main {
 
  private static void solve() {
    int n = ni();
    int X = ni();
    long[] x = nal(n);

    long gcd = Math.abs(x[0] - X);
    for (int i = 0; i < n; i ++) {
      x[i] -= X;
      gcd = gcd(gcd, Math.abs(x[i]));
    }
    System.out.println(gcd);
  }
  public static long gcd(long a, long b)
  {
    while(b > 0){long c = a; a = b; b = c % b; }
    return a;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }
 
  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;
 
  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
 
  private static double nd() {
    return Double.parseDouble(next());
  }
 
  private static long nl() {
    return Long.parseLong(next());
  }
 
  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }
 
  private static char[] ns() {
    return next().toCharArray();
  }
 
  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }
 
  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }
 
  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }
 
  private static int ni() {
    return Integer.parseInt(next());
  }
 
  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
 }

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  for (i = a; i <= b; i++) {
    if (!(a + k <= i && i <= b - k)) {
      cout << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    a = [0] + list(map(int, readline().split()))
    from collections import Counter
    b = [0] * (n + 1)

    cur = 0
    for i, x in enumerate(a):
        cur += x
        b[i] = (cur - i) % k

    counter = Counter()
    ans = 0
    for i, x in enumerate(b):
        if i >= k:
            counter[b[i - k]] -= 1
        ans += counter[x]
        counter[x] += 1

    print(ans)


if __name__ == '__main__':
    main()


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


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

    int n;
    cin >> n;

    s64 ans = 1;
    vs64 a(n);
    rep (i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << "0\n";
            return 0;
        }
    }

    s64 lim = 1e18;
    rep (i, n)
    {
        if (ans > lim / a[i] || ans * a[i] < 0 || ans * a[i] > lim)
        {
            cout << "-1\n";
            return 0;
        }
        ans *= a[i];
    }

    if (ans > lim || ans < 0) ans = -1;

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



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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int INF = 2e9 + 5;

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

    int n;
    cin >> n;

    vector<pair<int, int>> v, tmp;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back({x - y, x + y - 1});
    }

    sort(all(v));

    int mn = INF;
    for (int i = n - 1; i >= 0; i--) {
        if ((i == 0 || v[i - 1].first != v[i].first) &&
            mn > v[i].second) {
            tmp.push_back(v[i]);
            mn = v[i].second;
        }
    }

    v = tmp;

    reverse(all(v));

    int ans = 0, last = -INF;

    for (auto p : v) {
        if (p.first > last) {
            ans++;
            last = p.second;
        }
    }

    cout << ans;

    return 0;
}   

Measured memory_bytes: 2548
def main():
  def CalExVal(x):
    return (1/2*(x+1))
  N, K = map(int, input().split())
  A = list(map(int, input().split()))


  Ex = list((map(CalExVal, A)))
  #temp = len(A)-K + 1
  #adjlist = [0]*(temp)
  #adjlist = [sum(list(map(CalExVal, A))[i:(K+i)]) for i in range(temp)]
  tem = sum(Ex[:K])
  res = tem
  for i in range(0,N-K):
      tem = tem - Ex[i] + Ex[i+K]
      if res < tem:
      	res = tem
  print(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 25060
import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Created by Harry on 4/7/20.
 */
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        long N = scanner.nextLong();
        if(N==2){
            System.out.print(1);
            return;
        }
        long res = 2+count(N-1);
        for(long k=2; k<=Math.sqrt(N); k++){
            if((N-1)%k!=0 && isFeasible(N, k)){
                res++;
            }
        }
        System.out.print(res);
    }

    public static boolean isFeasible(long N, long k){
        if(N%k==0){
            while(N%k==0){
                N = N/k;
            }
            return N%k==1;
        }
        return false;
    }

    public static long count(long n){
        int res = 0;
        for(long i=2; i<=Math.sqrt(n); i++){
            if(n%i==0){
                res+=1;
                if(i*i!=n){
                    res++;
                }
            }
        }
        return res;
    }
}


Measured memory_bytes: 23764