akhauriyash/Code-Regression huggingface dataset:
import sys
from bisect import bisect_left

input = sys.stdin.readline


def binary_search(L, a, high):
    ng = -1
    ok = high
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if a <= L[mid]:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    L = [0] * N
    L[0] = A[0]
    length = 1
    for a in A[1:]:
        if L[length - 1] < a:
            L[length] = a
            length += 1
        else:
            j = bisect_left(L, a, hi=length)
            L[j] = a

    print(length)


if __name__ == "__main__":
    main()



Measured memory_bytes: 11060
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> B(N);
	map<int,int> A;
	for (int i = 0; i < N; ++i) {
		int ter;
		cin >> B[i];
		ter = B[i];

		if (A.find(ter) != A.end()) {
			A[ter]++;
		}
		else {
			A[ter] = 1;
		}
	}
	
	int ans = 0;
	map<int, int>::iterator itr;
	itr = A.begin();
	while(itr!=A.end())
	{
		int ter = itr->second;
		if (ter % 2 == 1) {
			++ans;
		}
		++itr;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int xx = 0, yy = 0, tt = 0, t, x, y;
		boolean b = true;
		for (int i = 0; i < n; i++) {
			t = sc.nextInt();
			x = sc.nextInt();
			y = sc.nextInt();
			if (t - tt - Math.abs(x - xx) - Math.abs(y - yy) >= 0
					&& (t - tt- Math.abs(x - xx) - Math.abs(y - yy)) % 2 == 0) {
				tt = t;
				xx = x;
				yy = y;
			} else {
				b = false;
				break;
			}
		}
		if (b) {
			sb.append("Yes");
		} else {
			sb.append("No");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 87660
n = int(input())
P = list(map(float, input().split()))

DP = [[0]*(n+1) for _ in range(n+1)]
DP[0][0] = 1

for i in range(n):
  for j in range(n+1):
    if j==0:
      DP[0][i+1] = DP[0][i] * (1-P[i])
    else:
      DP[j][i+1] = DP[j][i] * (1-P[i]) + DP[j-1][i] * P[i]

ans = 0
for k in range(n//2+1, n+1):
  ans += DP[k][n]

print(ans)

Measured memory_bytes: 206880
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    cout << n*(n+1)/2;
    
    cout << endl;
    return 0;
}

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

long long n, dp[100009][4], a[100009], b[100009], c[100009];
long long solve(long long x, int pre)
{
    if(x < 0)
        return 0;
    if(dp[x][pre] != -1)
        return dp[x][pre];
    if(pre != 1)
        dp[x][pre] = max(dp[x][pre], a[x] + solve(x - 1, 1));
    if(pre != 2)
        dp[x][pre] = max(dp[x][pre], b[x] + solve(x - 1, 2));
    if(pre != 3)
        dp[x][pre] = max(dp[x][pre], c[x] + solve(x - 1, 3));
    return dp[x][pre];
}
main()
{
    cin>>n;
    memset(dp, - 1, sizeof(dp));
    for(long long i = 0; i < n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<max(a[n - 1] + solve(n - 2, 1), max(b[n - 1] + solve(n - 2, 2), c[n - 1] + solve(n - 2, 3)));
}


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

int main(void){
   long long a,b;
   cin >> a >> b;
   if(a > 0){
       cout << "Positive" << endl;
   }else if(a == 0){
       cout << "Zero" << endl;
   }else{// a < 0
       if(b < 0){
           if((b - a + 1) % 2 == 0){
               cout << "Positive" << endl;
           }else{
               cout << "Negative" << endl;
           }
       }else{
           cout << "Zero" << endl;
       }
   }
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = -float('inf')
for i in range(N):
    cnt = 0
    k = 0
    done = set()
    S = []
    while i not in done:
        done.add(i)
        ni = P[i] - 1
        if len(S):
            S.append(S[-1] + C[ni])
        else:
            S.append(C[ni])
        i = ni
    if K <= len(S):
        score = max(S[:K])
    elif S[-1] <= 0:
        score = max(S)
    else:
        score1 = S[-1] * ((K // len(S)) - 1)
        score1 += max(S)
        score2 = S[-1] * (K // len(S))
        r = K % len(S)
        if r != 0:
            score2 += max(0, max(S[:r]))
        score = max(score1, score2)
    ans = max(ans, score)
print(ans)


Measured memory_bytes: 168580
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  using Pair = pair<ll, ll>;
  vector<ll> X, Y;
  vector<Pair> P;
  for (ll i = 0; i < N; i++) {
    ll x, y; cin >> x >> y;
    X.push_back(x);
    Y.push_back(y);
    P.emplace_back(x, y);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  // sort(P.begin(), P.end());
  ll ans = LLONG_MAX;
  for (ll i = 0; i < N; i++) {
    ll p = Y.at(i);
    for (ll j = i+1; j < N; j++) {
      ll q = Y.at(j);
      for (ll k = 0; k < N; k++) {
	ll r = X.at(k);
	for (ll l = k+1; l < N; l++) {
	  ll s = X.at(l);
	  ll cnt = 0;
	  for (ll m = 0; m < N; m++) {
	    ll x = P.at(m).first;
	    ll y = P.at(m).second;
	    if (r <= x && x <= s && p <= y && y <= q) cnt++;
	  }
	  if (cnt >= K) ans = min(ans, (q - p) * (s - r));
	}
      }
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

const int LOG = 29;
const int N = 2e5 + 5;

int n;
int a[N];
int b[N];

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d", &n);

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

    for(int i = 1;i <= n;i++) {
        scanf("%d", &b[i]);
    }

    int value = 0;

    for(int k = 0;k < LOG;k++) {
        vec< int > ar(n);
        for(int i = 0;i < n;i++) {
            ar[i] = b[i + 1] & ((1 << (k + 1)) - 1);
        }
        sort(ALL(ar));
        int tot = 0;
        for(int i = 1;i <= n;i++) {
            int x = a[i] & ((1 << (k + 1)) - 1);
            int tmp = 0;
            tmp += lower_bound(ALL(ar), (1 << (k + 1)) - x) - lower_bound(ALL(ar), (1 << k) - x);
            tmp += lower_bound(ALL(ar), (1 << (k + 2)) - x) - lower_bound(ALL(ar), ((1 << k) * 3) - x);
            tot ^= (tmp & 1);
        }
        if(tot) {
            value |= (1 << k);
        }
    }

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

    return 0;
}


Measured memory_bytes: 2560
'use strict'
function main(inp) {
  inp = inp.trim();
  let ans = "No";
  if(inp[0] == 7 || inp[1] == 7 || inp[2] == 7){
  	ans = "Yes"
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <random>
using namespace std;

typedef long long ll;

ll n;
string s;
ll q;

int Dpos[1000000] = {};
int DM[1000000] = {};

ll solve() {
    ll k;
    cin >> k;
    ll Dlive = 0;
    ll Dn = 0;
    ll tmp = 0;
    ll DMs = 0;
    ll DMC = 0;

    for (ll pos = 0; pos < n; pos++) {
        char c = s[pos];
        if (Dlive < Dn) {
            if (pos - Dpos[Dlive] >= k) {
                DMs -= tmp;
                tmp -= DM[Dlive];
                Dlive += 1;
            }
        }

        if (c == 'D') {
            Dpos[Dn] = pos;
            DM[Dn] = 0;
            Dn++;
        } else if (c == 'M') {
            if (Dn > 0) {
                DM[Dn - 1] += 1;
                tmp += 1;
            }
            DMs += Dn - Dlive;
        } else if (c == 'C') {
            DMC += DMs;
        }
    }

    return DMC;
}

int main() {
    cin >> n >> s >> q;
    while(q--) {
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 9204
N = int(input())
A = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  A.append((x,y))

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

A = sorted(A, key=lambda x: -x[1])
B = sorted(B, key=lambda x: x[0])
cnt = 0

for bx,by in B:
  can = None
  for i in range(len(A)):
    if A[i][0] < bx and A[i][1] < by:
      can = i
      break

  if can is not None:
    A.pop(can)
    cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en,h) for(int i=st; i<=en; i+=h)
#define eb emplace_back
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int n,m,_,ans,b,c;

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

	cin>>n>>m; UnionFind a(n);
	for (int j = 0; j < m; j++){
		cin>>b>>c>>_; a.unite(b-1,c-1);
	}
	map<int,int> s={};
	for (int i = 0; i < n; i++)s[a.find(i)]++;
	for(auto e:s)ans++;
	END
}

Measured memory_bytes: 5376
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = scanner.nextInt();
		}
		Arrays.parallelSort(H);
		long result = 0;
		for (int i = 0; i < N - K; i++) {
			result += H[i];
		}
		System.out.println(result);

	}

}


Measured memory_bytes: 64764
#ABCB - Bite Eating
N, L = list(map(int,input().split()))
all = 0
apple = []
for i in range(N):
    apple.append(L + i)
a = min(apple)
b = max(apple)
if 0 in apple:
    print(sum(apple))
elif b < 0:
    print(sum(apple)-b)
elif a > 0:
    print(sum(apple)-a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int Notprime[200005], Prime[200005], tot;
void Euler(int Max) {
  for (RI i = 2; i <= Max; ++i) {
    if (!Notprime[i]) Prime[++tot] = i;
    for (RI j = 1; j <= tot && i * Prime[j] <= Max; ++j) {
      Notprime[i * Prime[j]] = 1;
      if (i % Prime[j] == 0) break;
    }
  }
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  Euler(2e5);
  int n; cin >> n;
  for (RI i = 1; i <= tot; ++i)
    if (Prime[i] >= n) {
      cout << Prime[i] << endl;
      break;
    }

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0, c=T[u].l; c!=NIL; i++, c=T[c].r)
  {
    if(i)cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

//再帰的に深さを求め
void rec(int u, int p)
{
  D[u]=p;
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  cin >> n;

  for(i=0; i<n; i++)
    T[i].p=T[i].l=T[i].r=NIL;

  for(i=0; i<n; i++)
  {
    cin >> v >> d;
    for(j=0; j<d; j++)
    {
      cin >> c;
      if(j == 0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0; i<n; i++)
  {
    if(T[i].p == NIL)
      r=i;
  }

  rec(r, 0);

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

  return 0;
}



Measured memory_bytes: 7696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
struct Point { int x,y; };
vector<Point> ps;
vector<vector<int>> g;
vector<bool> used;

void dfs(int cur, int &cnt, set<int> &xs, set<int> &ys) {
    if (used[cur]) return;
    cnt++;
    used[cur] = true;
    xs.insert(ps[cur].x);
    ys.insert(ps[cur].y);

    for(int to : g[cur]) {
        dfs(to, cnt, xs, ys);
    }
}

int main(void){
    int n;
    cin >> n;
    ps.resize(n);
    g.resize(n);
    used.resize(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        ps[i] = {x,y};
    }

    vector<int> ord(n);
    iota(all(ord), 0);

    sort(all(ord), [&](int i, int j){
        return ps[i].x != ps[j].x ? ps[i].x < ps[j].x : ps[i].y < ps[j].y;
    });
    rep(i,n-1){
        if (ps[ord[i]].x == ps[ord[i+1]].x){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    sort(all(ord), [&](int i, int j){
        return ps[i].y != ps[j].y ? ps[i].y < ps[j].y : ps[i].x < ps[j].x;
    });
    rep(i,n-1){
        if (ps[ord[i]].y == ps[ord[i+1]].y){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    ll res = 0;
    rep(i,n){
        int cnt = 0;
        set<int> xs, ys;
        dfs(i, cnt, xs, ys);
        res += xs.size() * ys.size() - cnt;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<lint>;
const lint MOD = 1e9 + 7;
inline lint emod(lint x, lint p = MOD) {
  return (x % p + p) % p;
}
lint power(lint x, lint n, lint mod = numeric_limits<lint>::max()) {
  assert(n >= 0);
  if (n == 0) return 1;
  return power(x * x % mod, n / 2, mod) * (n % 2 ? x : 1) % mod;
}
inline lint inv(lint x, lint p = MOD) {
  assert((x %= p) != 0);
  return power(x, p - 2, p);
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  n++;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
  VL nC(n + 1, 1);
  for (int r = 0; r < n / 2; r++) {
    nC[r + 1] = nC[n - r - 1] = nC[r] * (n - r) % MOD * inv(r + 1) % MOD;
  }
  vector<bool> be(n);
  int d;
  for (int i = 0; i < n; i++) {
    if (be[a[i]]) {
      d = a[i];
      break;
    }
    be[a[i]] = true;
  }
  int l = -1, r;
  for (int i = 0; i < n; i++) {
    if (a[i] == d) {
      if (l == -1) {
        l = i;
      } else {
        r = i;
      }
    }
  }
  int m = n - (r - l) - 1;
  VL mC(n + 1, 0);
  fill(mC.begin(), mC.begin() + m + 1, 1);
  for (int r = 0; r < m / 2; r++) {
    mC[r + 1] = mC[m - r - 1] = mC[r] * (m - r) % MOD * inv(r + 1) % MOD;
  }
  for (int k = 1; k <= n; k++) {
    int res = emod(nC[k] - mC[k - 1]);
    cout << res << '\n';
  }
  return 0;
}


Measured memory_bytes: 3200
import math
n,m=map(int,input().split())
num=int(math.sqrt(m))
ans=1
for i in range(1,num+2):
    if m%i==0 and i>=n:
        ans=max(ans,m//i)
        break
    if m%i==0 and m//i>=n:
        ans=max(ans,i)
print(ans)


Measured memory_bytes: 9048
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        mut a: usize, mut b: usize, k: usize,
    }
    for i in 0..k {
        if i % 2 == 0 {
            b += a / 2;
            a /= 2;
        } else {
            a += b / 2;
            b /= 2;
        }
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1
    flag = "Init"
    for i in range(1, n):
        if flag == "Init":
            if a[i - 1] == a[i]:
                pass
            elif a[i - 1] > a[i]:
                flag = "-"
            else:
                flag = "+"
        elif flag == "-":
            if a[i - 1] < a[i]:
                ans += 1
                flag = "Init"
        else:
            if a[i - 1] > a[i]:
                ans += 1
                flag = "Init"
    print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
ll gcd(ll a, ll b){
    if (a < b)
        gcd(b, a);
    ll r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>A(n);
    REP(i,n){
        cin >> A[i];
    }
    int t;
    REP(i, n - 1)
    {
        A[i + 1] = gcd(A[i], A[i + 1]);
    }
    cout << A[n - 1] << endl;
}

Measured memory_bytes: 640
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
k,x = map(int,input().split())

st = x-k+1
end = x+k

ans = list(range(st,end))

print(*ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    forn (i, 0, 3)
        cout << s[i];
    return 0;
}

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

int n, k, h[100009], dp[100009];

int call(int i)
{
    if(i == n-1)
        return dp[i] = 0;

    if(dp[i] != -1)
        return dp[i];

    dp[i] = INT_MAX;
    for(int j = 1; j <= k && i+j < n; j++)
        dp[i] = min(dp[i], call(i+j) + abs(h[i]-h[i+j]));

    return dp[i];
}

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

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

    memset(dp, -1, sizeof dp);
    cout << call(0);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

int main(){
    ll n; cin >> n;
    P r[n];
    rep(i, n) {
        ll x, l; cin >> x >> l;
        r[i].first = x+l;
        r[i].second = x-l;
    }
    sort(r, r+n);

    ll ans = 0, last = LLONG_MIN;
    rep(i, n){
        if(last <= r[i].second){
            ans++;
            last = r[i].first;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a = n % 10;
    n = n / 10;
    int b = n % 10;
    n = n / 10;
    int c = n % 10;
    if (a == 7 || b == 7){
        cout << "Yes";
    }else if (c == 7){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N;
  cin >> N;
  vector<pair<string, int>> bs(N);
  REP(i, N) cin >> bs.at(i).fst >> bs.at(i).snd;

  VP ans(N);
  REP(i, N){
    ans.at(i).snd=i+1;
    int cnt=1;
    REP(j, N){
      if((bs.at(i).fst>bs.at(j).fst||
      (bs.at(i).fst==bs.at(j).fst&&bs.at(i).snd<bs.at(j).snd))&&i!=j) cnt++;
    }
    ans.at(i).fst=cnt;
  }

  SORT(ans);

  REP(i, N) cout << ans.at(i).snd << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  ll N, K;
  std::cin >> N >> K;

  std::vector< ll > vh(N, 0);
  for (ll i = 0; i < N; i++) {
    std::cin >> vh[i];
  }

  std::sort(vh.begin(), vh.end());

  ll ans = INF;
  for (ll i = 0; i < N-K+1; i++) {
    ll diff = vh[i+K-1] - vh[i]; 
    ans = diff < ans ? diff : ans;
  }

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


Measured memory_bytes: 1024
n = int(input())
lis = map(int, input().split())

fil = list(filter(lambda x: x % 2 == 0, lis))


def soinsuu(giv):
    co = 0
    while True:
        if giv % 2 == 1:
            break
        giv /= 2
        co += 1

    return co


count = 0
for i in fil:
    import math
    count += int(soinsuu(i))
print(count)


Measured memory_bytes: 4144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int[] a = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
        Array.Sort(a);
        if (a[0] == a[1] && a[0] != a[2])
        {
            Console.WriteLine("Yes");
            return;
        }
        if (a[1] == a[2] && a[0] != a[1])
        {
            Console.WriteLine("Yes");
            return;
        }
        Console.WriteLine("No");
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }

    static long RepeatedSquare(long n, long p, long m)
    {
        if (p == 0) return 1;
        if (p % 2 != 0) return n * RepeatedSquare(n, p - 1, m);
        long t = RepeatedSquare(n, p / 2, m);
        return (t * t) % m;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13268
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static int N;
    static int K;
    static int Q;
    static int A;
    static long B;
    static long C;
    //    static int[][] map;
    static int min = 9999999;
    static long ans = 0;


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

        int[] map = new int[3];

        map[0] = scanner.nextInt();
        map[1] = scanner.nextInt();
        map[2] = scanner.nextInt();

        Arrays.sort(map);

        System.out.println(map[2] * 10 + map[1] + map[0]);

    }
}



Measured memory_bytes: 23252
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var jobs = Enumerable.Range(0, N).Select(_ => new Job(Console.ReadLine().Split())).OrderBy(s => s.Limit);

            long sum = 0;
            foreach (var job in jobs)
            {
                sum += job.Time;
                if (sum > job.Limit)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }

    class Job
    {
        public long Time { get; set; }
        public long Limit { get; set; }

        public Job(string[] input)
        {
            Time = long.Parse(input[0]);
            Limit = long.Parse(input[1]);
        }
    }
}


Measured memory_bytes: 31404
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        long[] sum = new long[n];
        long res = 0;
        long diff;
        for (int i = n - 1; i >= 0; i--) {
            a[i] = a[i] + sum[i];
            diff = (a[i] + b[i] - 1) / b[i] * b[i] - a[i];
            res += diff;
            if (i > 0) {
                sum[i - 1] = sum[i] + diff;
            }
        }
        System.out.println(res);
    }
}

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


using namespace std;
using ll = long long;

ll n , k;

main(){
    scanf("%lld %lld" , &n , &k);

    ll ans = k;
    ans *= ceil(pow(k-1 , n-1));
    printf("%lld\n" , ans);

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll A, B, N;

int main() {

	cin >> A >> B >> N;

	ll x = min(N, B - 1);

	cout << A * x / B - A * (x / B) << endl;

	return 0;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
  string s,t;
  cin>>s>>t;
  int ls=s.length();
  int lt=t.length();
  vector<vector<int>> g(ls*2+1,vector<int>(33,0));
  int lst[33]={};
  if(1){
    map<char,int> mp;
    FOR(i,0,lt){
      mp[t[i]]++;
    }
    FOR(i,0,ls){
      mp[s[i]]=0;
    }
    for(const auto&x:mp){
      if(x.ND>0){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  string ss=s+s;
  FORD(i,ls,0){
    lst[s[i]-'a']=i+ls;
  }
  FORD(i,ls,0){
    FOR(j,0,'z'-'a'+1){
      g[i][j]=lst[j]-i;
    }
    lst[s[i]-'a']=i;
  }
  int nw;
  LL ans=0;
  FOR(i,0,ls){
    if(s[i]==t[0]){
      nw=i;
      ans=i;
      break;
    }
  }
  FOR(i,1,lt){
    int nxc=t[i]-'a';
    int cs=g[nw][nxc];
    ans+=cs;
    nw=(nw+cs)%ls;
  }
  cout<<ans+1<<endl;

	return 0;
}


Measured memory_bytes: 33536
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define ma 100000000
#define mod 1000000007
#define Nmax 1000000000000
using namespace std;

int main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    string a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll dp[n][m];
    memset(dp,0,sizeof dp);
    dp[n-1][m-1]=0;
    for(int i=n-2;i>=0 && a[i][m-1]!='#';i--) {dp[i][m-1]=1;}
    for(int i=m-2;i>=0 && a[n-1][i]!='#';i--) dp[n-1][i]=1;
    for(int i=n-2;i>=0;i--){
        for(int j=m-2;j>=0;j--){
            if(a[i][j]=='#') dp[i][j]=0;
            else dp[i][j]=dp[i+1][j]+dp[i][j+1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[0][0];
    return 0;
}


Measured memory_bytes: 9088
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

#define ll long long
#define Max 200005

using namespace std;

inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
    ll x=0;char ch=gc();bool positive=1;
    for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
    for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
    return positive?x:-x;
}

inline void write(ll x){
    if(x<0)x=-x,putchar('-');
    if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
    write(x);puts("");
}

ll n,ans,sum,a[Max];

int main(){
    n=read();
    for(ll i=1;i<=n;i++)a[i]=read()-i;
    sort(a+1,a+n+1);
    for(ll i=1;i<=n;i++){
        ans+=abs(a[i]-a[n/2]);
        sum+=abs(a[i]-a[n/2+1]);
    }
    writeln(min(ans,sum));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(ll (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(ll (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; ll lim;
    cin >> n >> lim;
    VL w(n);
    vector<VL> v(4);
    int V;
    FOR(i, 0, n) {
        cin >> w[i] >> V;
        v[w[i] - w[0]].push_back(V);
    }
    FOR(i, 0, 4) {
        rSORT(v[i], greater<ll>());
        FOR(j, 1, v[i].size())v[i][j] += v[i][j - 1];
    }

    ll ans = 0;
    eFOR(a, 0, v[0].size())eFOR(b, 0, v[1].size())eFOR(c, 0, v[2].size())eFOR(d, 0, v[3].size()) {
        ll cost = 0;
        cost += a * w[0];
        cost += b * (w[0] + 1);
        cost += c * (w[0] + 2);
        cost += d * (w[0] + 3);
        if (cost > lim)continue;
        ll sum = 0;
        if (0 < a)sum += v[0][a - 1];
        if (0 < b)sum += v[1][b - 1];
        if (0 < c)sum += v[2][c - 1];
        if (0 < d)sum += v[3][d - 1];
        chmax(ans, sum);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int N = scan.nextInt();
		int[][] XY = new int[N][2];		//観光地
		int[] S = new int[2];		//スタート地点
		int cnt = 0;

		for(int i = 0; i < N; i++){
			int x = scan.nextInt();
			int y = scan.nextInt();
			XY[i][0] = x;
			XY[i][1] = y;
		}
		S[0] = XY[0][0];
		S[1] = XY[0][1];

		int i = 0;
		while(i < N){
			if((S[0] == XY[i][0]) && (S[1] == XY[i][1])){
				i++;
				continue;
			}else{
				if(S[0] < XY[i][0]){		//スタート地点より観光地が右側
					if(S[1] < XY[i][1]){		//スタート地点より観光地の方が右上
						S[0]++;
						S[1]++;
					}else{		//右側
						S[0]++;		//横右移動
					}
					cnt++;
				}
				if(S[0] > XY[i][0]){		//スタート地点より観光地の方が左側
					if(S[1] > XY[i][1]){		//スタート地点より観光地の方が左下
						S[0]--;
						S[1]--;
					}else{		//左側
						S[0]--;		//横左移動
					}
					cnt++;
				}
				if(S[0] == XY[i][0]){		//上下
					if(S[1] < XY[i][1]){		//上側
						S[1]++;
						cnt++;
					}else if(S[1] > XY[i][1]){		//下側
						S[1]--;
						cnt++;
					}if(S[1] == XY[i][1]){
						i++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 25668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
    string S;
    cin>>S;
    bool ans=false;
    for(char i='a'; i<='z'; i++){
        if(S.find(i)==-1){
            cout<<i<<endl;
            ans=true;
          	break;
        }
    }
    if(ans==false){
        cout<<"None"<<endl;
    }
    }


Measured memory_bytes: 3720
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

signed main (){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    rep(i,0,m)cin>>b[i];
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,0,n){
        rep(j,0,m)cin>>a[i][j];
    }

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

    

    
}  
/*

*/


Measured memory_bytes: 256
n = gets.to_i
ss = gets.chomp.chars
ans = ss.count("R") * ss.count("G") * ss.count("B")

0.upto(n) do |i|
  1.upto(n / 2) do |d|
    j = i + d
    k = i + d * 2
    next unless k < n

    a = ss[i]
    b = ss[j]
    c = ss[k]
    ans -= 1 if a != b && b != c && c != a
  end
end

puts ans


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

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2364 : Lucky Dip **/
int field[1000][1000];
int d[1000][1000];
const int GOAL = 10000;
int W, H, N;


bool search(int n)
{
	fill(d[0], d[0]+1000*1000, INF);
	
	queue<P> Q;
	Q.push(P(0,0));
	d[0][0] = 1;
	
	while (Q.size()) {
		P p = Q.front(); Q.pop();
		
		rep(i, 4) {
			int nx=p.first+dx[i], ny=p.second+dy[i];
			if_range(nx, ny, W, H) {
				if (field[nx][ny]==GOAL)
					return true;
				
				if (field[nx][ny] <= n && d[nx][ny]==INF) {
					Q.push(P(nx, ny));
					d[nx][ny]=d[p.first][p.second]+1;
				}
			}
		}
	}
	
	return false;
}

int main()
{
	cin>>W>>H;
	rep(y, H) {
		rep(x, W) {
			char c;
			cin>>c;
			if (c=='.')
				field[x][y]=0;
			else if (c=='#')
				field[x][y]=INF;
			else if (c=='t')
				field[x][y]=GOAL;
		}
	}
	
	if (search(0)) {
		cout << 0 << endl;
		return 0;
	}
	
	cin>>N;
	int i=1;
	for (;i<N+1;i++) {
		int xx, yy;
		cin >> xx >> yy;
		if (field[xx][yy]==INF)
			field[xx][yy]=i;
	}
	
	int lb=0, ub=1100, mid;
	while (ub-lb>1) {
		mid=(lb+ub)/2;
		if (search(mid))
			ub=mid;
		else
			lb=mid;
	}
	
	if (ub>N)
		cout << -1 << endl;
	else
		cout << ub << endl;
	
	return 0;
}

Measured memory_bytes: 9040
import string

def main():
    s, t = input(), input()
    ans = 'Yes' if solve(s, t) else 'No'
    print(ans)


def solve(s, t):
    if len(s) + 1 != len(t):
        return False
    for i, j in zip(s, t):
        if i != j:
            return False
    return True


if __name__ == '__main__':
    main()

Measured memory_bytes: 9912
import itertools


DEF_MODULO = 10 ** 9 + 7


def solve(n, m, ss, ts, mod = DEF_MODULO):
    dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
    for i, j in itertools.product(range(n), range(m)):
        if ss[i] == ts[j]:
            dp[i + 1][j + 1] = 1 + dp[i + 1][j] + dp[i][j + 1]
        else:
            dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j]
        dp[i + 1][j + 1] %= mod
    return (dp[n][m] + 1) % mod


def main():
    n, m = (int(z) for z in input().split())
    ss = [int(s) for s in input().split()]
    ts = [int(t) for t in input().split()]
    res = solve(n, m, ss, ts)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 74716
import java.util.*;
import java.io.*;

/*
   AtCoder contest
   coder : yoichidon
 */

public class Main {
    // calc the index where array[i] is minimum of array, except [currentIndex]
    public static void open(LinkedList<Integer> operations, int boxes, int current, int end){
        for(int b=0; b<boxes; b++) if(b!=current && b!=end) operations.addLast(b+1); // 1-index
        operations.add(end+1);
    }
    public static void open(LinkedList<Integer> operations, int boxes, int end){
        open(operations, boxes, -1, end);
    }

    public static int minIndex(int[] array, int currentIndex){
        int min = Integer.MAX_VALUE;
        int ans = -1;
        for(int i=0; i<array.length; i++){
            if(i!=currentIndex && array[i]<min){
                min = array[i];
                ans = i;
            }
        }
        return ans;
    }
    public static int minIndex(int[] array){
        return minIndex(array, -1);
    }

    public static void impossible(){
        System.out.println(-1);
        System.exit(0);
    }
    public static void possible(LinkedList operations){
        System.out.println(operations.size());
        while(!operations.isEmpty()){
            System.out.print(operations.pop());
            if(operations.isEmpty()) System.out.println();
            else System.out.print(" ");
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for(int n=0; n<N; n++) A[n] = sc.nextInt();

        LinkedList<Integer> operations = new LinkedList<>();
        int current = -1;
        for(int k=0; k<=K; k++){
            int end = minIndex(A, current);
            open(operations, N, current, end);
            for(int n=0; n<N; n++) if(n!=current) {
                A[n]--;
                if(A[n]<0) impossible();
            }
            current=end;
        }

        possible(operations);

    }
}


Measured memory_bytes: 25812
#include <iostream>
#include <cmath>

using namespace std;

int main()
{

    int n;

    cin >> n;

    int h[n+1], i;

    for(i = 1 ; i <= n ; i++)
        cin >> h[i];

    int dp[n+1];

    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for(i = 3 ; i <= n ; i++)
        dp[i] = min (dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));

    cout << dp[n] ;
    return 0;
}


Measured memory_bytes: 1024