akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    string s; cin >> s;
    int ans = 0, cnt = 0;
    bool flg = true;
    rep(i, s.size()) {
        if(flg){
            if(s[i] == 'g') {
                ++cnt;
            }else {
                --cnt;
            }
        }
        if(!flg && s[i] == 'g')
            ++ans;
        if(cnt >= s.size() - i - 1)
            flg = false;
    }
    cout << ans << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int64 N;
  cin >> N;
  vector<PLL> xy(N);
  REP(i, N) cin >> xy[i].fs >> xy[i].sc;
  sort(all(xy));
  int64 res = INF;
  REP(i, N) {
    REP(j, N) {
      int64 p = xy[j].fs-xy[i].fs, q = xy[j].sc-xy[i].sc;
      map<PLL, int> mp;
      int64 cnt = 0;
      REP(k, N) {
        int a = mp[PLL(xy[k].fs-p, xy[k].sc-q)];
        int b = mp[PLL(xy[k].fs+p, xy[k].sc+q)];
        if (a > 0 || b > 0) {
          if (a > 0 && b > 0) cnt--;
        } else {
          cnt++;
        }
        mp[PLL(xy[k].fs, xy[k].sc)] = 1;
      }
      res = min(res, cnt);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
def sum(N):
    sum = 0
    while N > 0:
        sum += N%10
        N = N//10
    return sum

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

ans = 0

for n in range(1, N+1):
    if A <= sum(n) <= B:
        ans += n

print(ans)

Measured memory_bytes: 9176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
using ll = long long;
const ll ha = 1000000007LL;
typedef ll Mat[3][3];
void mat_mul(Mat A, Mat B, int n, int m, int p, Mat &res) {
  static Mat C; memset(C, 0, sizeof(C));
  for(int i = 0; i < n; i ++) {
    for(int j = 0; j < p; j ++) {
      for(int k = 0; k < m; k ++) {
        C[i][j] += A[i][k] * B[k][j] % ha;
        if(C[i][j] >= ha) C[i][j] -= ha;
      }
    }
  }
  memcpy(res, C, sizeof(C));
}
void mat_pow(Mat A, int n, int c, Mat &res) {
  static Mat C, a; memset(C, 0, sizeof(C));
  for(int i = 0; i < n; i ++) C[i][i] = 1;
  memcpy(a, A, sizeof(a));
  while(c) {
    if(1 & c) mat_mul(C, a, n, n, n, C);
    mat_mul(a, a, n, n, n, a); c >>= 1;
  }
  memcpy(res, C, sizeof(C));
}

Mat A, C, T, B;
std::vector<int> V;
int main() {
  int n, m; scanf("%d%d", &n, &m);
  for(int i = 1; i <= m; i ++) {
    int x; scanf("%d", &x);
    V.push_back(x);
  }
  V.push_back(n);
  int las = 0;
  A[0][0] = 1;
  A[1][0] = 2; A[1][1] = 1;
  A[2][0] = A[2][1] = A[2][2] = 1;
  C[0][0] = C[0][2] = C[1][1] = C[2][2] = 1;
  mat_mul(C, A, 3, 3, 3, C);
  ll ans = 1LL;
  B[0][0] = 1; B[1][0] = B[2][0] = 0;
  for(int x : V) {
    mat_pow(C, 3, x - las - 1, T);
    mat_mul(A, T, 3, 3, 3, T);
    mat_mul(T, B, 3, 3, 1, B);
    las = x;
  }
  printf("%lld\n", B[2][0]);
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#define ll long long

int main(){
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
    int s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;

}

Measured memory_bytes: 3640
/*
AizuOnline A0087
Title: Strange Mathematical Expression

13/02/09 WA
13/02/10 unary operator - 
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
double STACK[100];
int SP;
char wk[100];
//
int is_op(char * c)
{
  return(((*c=='*'||*c=='+'||*c=='-'||*c=='/')&&(!isdigit(c[1]))));
}
void operate(char op)
{
  double res;
  //printf("OP\n");
  if(op=='+')
    res = STACK[SP-2]+STACK[SP-1];
  if(op=='-')
    res = STACK[SP-2]-STACK[SP-1];
  if(op=='*')
    res = STACK[SP-2]*STACK[SP-1];
  if(op=='/')
    res = STACK[SP-2]/STACK[SP-1];

  STACK[SP-2]=res;
  SP--;
}

print()
{
  int i;
  for(i=0;i<=5;i++)
    printf("%f:",STACK[i]);
  printf("\n");
}

main()
{
  char *tp;

  SP = 0;
  while(NULL != fgets(wk,100,stdin))
    {
      tp = strtok(wk," ");
      while(tp != NULL)
	{
	  if(is_op(tp))
	    operate(tp[0]);
	  else
	    {
	      sscanf(tp,"%lf",&(STACK[SP]));
	      SP++;
	    }
	  //print();
	  tp=strtok(NULL," ");
	}
      printf("%lf\n",STACK[0]);
      SP=0;
    }

return(0);
}

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

int main() {
  int N;
  cin >> N;
  
  bool four = false;
  
  for ( int i = 0; i < N; i++ ) {
    string S;
    cin >> S;
    
    if ( S == "Y" ) {
      four = true;
    }
  }
  
  if ( four ) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
  
}

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

int main() {
    int s, t;
    vector<int> v(5);
    while (cin >> s >> t, v[0] = s + t) {
        for (int i = 1; i < 5; i++) cin >> s >> t, v[i] = s + t;
        auto it = max_element(v.begin(), v.end());
        cout << (char)('A' + (it - v.begin())) << " " << *it << endl;
    }
    return 0;
}


Measured memory_bytes: 3052
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a + b) % 2:
        print("IMPOSSIBLE")
        return
    print((a + b) // 2)
    return

#B
def B():
    n = II()
    p = LI()
    for j in range(n - 1):
        if p[j] > p[j + 1]:
            break
    else:
        print("YES")
        return
    for i in range(n):
        for k in range(i+1, n):
            pi = p[::1]
            pi[i], pi[k] = pi[k], pi[i]
            for j in range(n-1):
                if pi[j] > pi[j + 1]:
                    break
            else:
                print("YES")
                return
    print("NO")
    return

#C
def C():
    n = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(n):
        if a[i] >= b[i]:
            ans += b[i]
            continue
        ans += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            ans += b[i]
            a[i + 1] -= b[i]
            continue
        ans += a[i + 1]
        a[i + 1] = 0
    print(ans)
    return

#D
def D():
    s = S()
    s = s[::-1]
    dp = [[0] * 13 for _ in range(len(s))]
    remain = 1
    if s[0] == "?":
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
    for i in range(1, len(s)):
        remain = (remain * 10) % 13
        dpi = dp[i]
        dpi1 = dp[i-1]
        if s[i] == "?":
            for k in range(10):
                for j in range(13):
                    dpi[(j + remain * k) % 13] += dpi1[j]
                    dpi[(j + remain * k) % 13] %= mod
        else:
            for j in range(13):
                dpi[(j + remain * int(s[i])) % 13] += dpi1[j]
    print(dp[-1][5])
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()


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

const int INF = 1 << 30;

struct Primal_Dual
{
  typedef pair< int, int > Pi;
  
  struct edge
  {
    int to, cap, cost, rev;
  };
  vector< vector< edge > > graph;
  vector< int > potential, min_cost, prevv, preve;
  
  Primal_Dual(int V):graph(V){}
  
  void add_edge(int from, int to, int cap, int cost)
  {
    graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});
    graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});
  }
  
  int min_cost_flow(int s, int t, int f)
  {
    int V = graph.size(), ret = 0;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, 0);
    preve.assign(V, -1);
    prevv.assign(V, -1);
  
    while(f > 0){
      min_cost.assign(V, INF);
      que.push(Pi(0, s));
      min_cost[s] = 0;
  
      while(!que.empty()){
        Pi p = que.top(); que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++){
          edge& e = graph[p.second][i];
          int nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost){
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.push(Pi(min_cost[e.to], e.to));
          }
        }
      }
      if(min_cost[t] == INF) return -1;
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      int addflow = f;
      for(int v = t; v != s; v = prevv[v]){
        addflow = min( addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v]){
        edge& e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return ret;
  }
};

int main()
{
  int N;
  while(cin >> N, N) {
    Primal_Dual FlowGraph(367);
    for(int i = 0; i < N; i++) {
      int x, y, w;
      cin >> x >> y >> w;
      FlowGraph.add_edge(x, y + 1, 1, -w);
    }
    for(int i = 0; i < 366; i++) {
      FlowGraph.add_edge(i, i + 1, INF, 0); 
    }
    cout << -FlowGraph.min_cost_flow(0, 366, 2) << endl;
  }
}

Measured memory_bytes: 1324
n,m=map(int,input().split())
mod=10**9+7
from math import factorial as f

if abs(n-m)>1:
    print(0)
    exit()
if n!=m:
    print((f(n)%mod)*(f(m)%mod)%mod)
else:
    print(2*(f(n)%mod)*(f(m)%mod)%mod)

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

int main(){
    
    int A,B;
    map<int,int>mp;
    for(int i = 0; i < 3;i++){
        cin >> A >> B;
        mp[A]++;
        mp[B]++;
    }
    
    if(mp[1]<=2
    && mp[2]<=2
    && mp[3]<=2
    && mp[4]<=2)cout << "YES"<<endl;
    else cout <<"NO"<<endl;
    
    
}
    
    



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int w[334],dp[334][334];
bool done[334][334],memo[334][334],fini[334][334];

bool search(int i, int j){
	int k;
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	if(i == j){
		memo[i][j] = false;
		return memo[i][j];
	}
	if((j-i)==1){
		memo[i][j] = (abs(w[i] - w[j])<=1);
		return memo[i][j];
	}
	if(abs(w[i] - w[j])<=1 && search(i+1,j-1)){
		memo[i][j] = true;
		return memo[i][j];
	}
	memo[i][j] = false;
	for(k=i; k<j; ++k){
		if(search(i,k) && search(k+1,j)){
			memo[i][j] = true;
			break;
		}
	}
	return memo[i][j];
}

int solve(int i, int j){
	int k;
	if(fini[i][j]){
		return dp[i][j];
	}
	fini[i][j] = true;
	if(search(i,j)){
		dp[i][j] = (j-i+1);
		return dp[i][j];
	}else if(i == j){
		dp[i][j] = 0;
		return dp[i][j];
	}
	dp[i][j] = 0;
	for(k=i; k<j; ++k){
		dp[i][j] = max(dp[i][j],solve(i,k)+solve(k+1,j));
	}
	return dp[i][j];
}

int main(void){
	int n,i,j;
	cin >> n;
	while(n){
		fill(done[0],done[334],false);
		fill(fini[0],fini[334],false);
		for(i=0; i<n; ++i){
			cin >> w[i];
		}
		for(i=0; i<n; ++i){
			for(j=i; j<n; ++j){
				search(i,j);
			}
		}
		cout << (solve(0,n-1)) << endl;
		cin >> n;
	}
	return 0;
}



Measured memory_bytes: 3800
N, M = map(int, raw_input().split())
kotae = [0]*N
for i in range(M):
 l=map(int, raw_input().split())
 for j in range(len(l)):
  kotae[l[j]-1]=kotae[l[j]-1]+1
for k in range(N):
 print kotae[k]

Measured memory_bytes: 2568
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

int n;
int r[10000];


class node{
public:
  int key;
  int p;
};

node t[10000];


int find(int x){
  int tmp[10000], i = 0;
  while(t[x].p != x){
    x = t[x].p;
    tmp[i++] = x;
  }
  for(int j = 0; j < i; j++){
    t[tmp[j]].p = x;
  }
  return x;
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(r[x] == r[y]){
    t[y].p = x;
    r[x]++;
  }
  else if(r[x] > r[y]) t[y].p = x;
  else t[x].p = y;
}

void same(int x, int y){
  if(find(x) == find(y)) cout << 1 << endl;
  else cout << 0 << endl;
}

int main(){

  cin >> n;


  for(int i = 0; i < n; i++){
    t[i].key = i;
    t[i].p = i;
    r[i] = 0;
  }

  int q;
  cin >> q;

  for(int i = 0; i < q; i++){
    int c, x, y;
    cin >> c >> x >> y;
    if(c == 0) unite(x, y);
    else same(x, y);
  }

  return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<math.h>
#include<string.h>

int main(void)
{
    unsigned long long int num, tmp;
    int n, ans, x;
    int dig[8];
    int i, j, k, l;

    scanf("%d", &n);

    for (i = 0;i < n;i++){
        scanf("%llu", &num);
        printf("Case %d:\n", i + 1);

        for (j = 0;j < 10;j++){
            ans = 0;
            num = pow(num,2);

            tmp = num;
            
            for (k = 0;k < 8;k++){
                dig[k] = tmp%10;
                tmp /= 10;
            }
            x = 1;
            
            for (l = 2;l < 6;l++){
                ans += dig[l] * x;
                x *= 10;
            }
            printf("%d\n", ans);
            num = ans;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,i,dp[200005],ans=0;
int main(){
   cin>>n;
   dp[0]=1;
   for(i=1;i<=n;i++) 
   {  
      cin>>a[i];
   	 if(dp[a[i]-1])dp[a[i]]=1;
   }
    for(i=n;i>=1;i--) 
   {  
   	 if(dp[i]==1)
		{
		ans=i;break;	
		}
   }
   if(i==0)cout<<-1;
   else
      cout<<n-ans;
}

Measured memory_bytes: 1792
import math
import bisect
#下準備
num = (10**5) + 2
#エラトステネス
era = [i for i in range(3,num,2)]
i = 0
while era[i] <= math.sqrt(num):
    tmp = era[i]
    era = [j for j in era if j % era[i] != 0]
    era.insert(i,tmp)
    i += 1
#もう一個の奴もやる

era = [j for j in era if bisect.bisect_left(era,(j+1) // 2) != bisect.bisect_right(era,(j+1)//2)]
era.insert(0,3)
#ans[i] => iまでの、目的を満たす数字の個数
q = int(input())
for i in range(q):
    l,r = list(map(int, input().split()))
    print(bisect.bisect_right(era,r) - bisect.bisect_left(era,l))


Measured memory_bytes: 5400
D, G = list(map(int, input().split()))
pc = []
for n in range(D):
    p, c = map(int, input().split())
    pc.append([p, c, p * (n + 1)*100 + c])

ans = sum(pc[:][0])
for i in range(2 ** D):
    temp = 0
    numberProb = 0
    box = ["-"] * D
    for j in range(D):
        if ((i >> j) & 1):
            box[D - j - 1] = "+"
    for k, l in enumerate(box):
        if l == "+":
            temp += pc[k][2]
            numberProb += pc[k][0]

    if temp >= G:
        ans = min(ans, numberProb)
    else:
        lisind = max( [i for i, x in enumerate(box) if x == '-'])
        for m in range(pc[lisind][0]):
            temp += (lisind + 1) * 100
            numberProb += 1
            if temp >= G:
                ans = min(ans, numberProb)
                break

print(ans)

Measured memory_bytes: 43740
n,k,*a=map(int, open(0).read().split())
b=[0]*-~n
for i in range(n):b[i+1]=(a[i]+b[i]-1)%k
d={k:0}
a=0
for l,r in zip([k]*min(k,n+1)+b,b):d[l]-=1;t=d.get(r,0);a+=t;d[r]=t+1
print(a)

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();
        final char[] ATCG_CHARS = { 'A', 'C', 'G', 'T' };

        int maxLength = 0;
        int currentLength = 0;
        for (char c : text) {
            if (Arrays.binarySearch(ATCG_CHARS, c) >= 0) {
                currentLength++;
            } else {
                maxLength = Math.max(currentLength, maxLength);
                currentLength = 0;
            }
        }
        System.out.println(Math.max(currentLength, maxLength));
    }
}

Measured memory_bytes: 21588
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var N = parseInt(input[0][0], 10);
    var vec_A = input[1].map(e => parseInt(e, 10));
    var tmp = vec_A[0];
    for (var i = 1; i < N; i++){
        tmp = saidaiKoyaku(tmp, vec_A[i]);
    }

    console.log(tmp);
}


function saidaiKoyaku(x, y){
    if (x < y) [x, y] = [y, x];
    var tmp1 = x;
    var tmp2 = y;
    while (tmp2 != 0){
        [tmp1, tmp2] = [tmp2, tmp1 % tmp2];
    }
    return tmp1;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 41128
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
int main(){
    rep(i,9){
        rep(j,9){
            cout << i + 1 << "x" << j + 1 << "=" << i * j + i + j + 1 << endl;
        }
    }
}


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

int main()
{
    string S, T; cin >> S;
    cin >> T;
    ll ans = 0;
    rep(i, S.length()) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << endl;

 
    




}


Measured memory_bytes: 3852
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)


// double c(double x)
// {
//   double X = x;
//   X = int(X) % 10;
//   return X;
// }

int main()
{
  ll n,k;
  cin >> n >> k;
  vector<ll> h(n);
  for(ll i = 0;i < n;i++)
  {
    cin >> h[i];
  }
  sort(h.rbegin(),h.rend());
  for(ll i = 0;i < min(k,n);i++)
  {
    h[i] = 0;
  }
  ll sum = 0;
  for(ll i = 0;i < n;i++)
  {
    sum += h[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long lst=(long long)1<<40,ans=(long long)1<<40,n;
inline long long read(){
	long long red=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-f;ch=getchar();}
	while (ch>='0'&&ch<='9') red=red*10+ch-'0',ch=getchar();
	return red*f;
}
int main(){
	n=read();ans=-ans;
	for (int i=1;i<=n;i++){
		long long x=read();
		ans=max(ans,x-lst);
		lst=min(lst,x);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3240
N=int(input())
num=["3","5","7"]

que=["3","5","7"]
count=0
for i in range(10**9):
  p=que.pop(0)
  for s in num:
    now=p+s
    #print(now)
    if int(now)>N:
      print(count)
      exit()
    que.append(now)
    if len(set(now))==3:
      count+=1
  

Measured memory_bytes: 4340
def examB():
    S = SI(); N = len(S)
    ans = 1000
    for i in range(N-2):
        cur = int(S[i:i+3])
        ans = min(ans,abs(753-cur))
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 38256
n, m = map(int, input().split())
ps_lis = []
for i in range(m):
    p, s = input().split()
    ps_lis.append([int(p), s])
ac_lis = [0] * (n + 1)
pe_lis = [0] * (n + 1)
for p, s in ps_lis:
    if s == 'WA' and ac_lis[p] == 0:
        pe_lis[p] += 1
    elif s == 'AC':
        ac_lis[p] = 1
for i, ac in enumerate(ac_lis):
    if ac == 0:
        pe_lis[i] = 0
print(sum(ac_lis), sum(pe_lis))        

Measured memory_bytes: 23592
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    long long n, k, sum = 0, mxsum = 0;
    double ans = 0;
    cin >> n >> k;
    vector<int>as(n);
    map<int, int> cnt;
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    for (int i = 0; i < k; i++){
        sum += as[i];
        mxsum += as[i];
    }
    for (int i = 0; i < n - k; i++){
        if (mxsum < sum - as[i] + as[i + k]){
            mxsum = sum - as[i] + as[i + k];
        }
        sum = sum - as[i] + as[i + k];
    }
    cout << (mxsum + k) / 2.0 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
ll mod = inf;
ll dp[110][10];
map<int,ll> p;
int main(){
    int h,w,K;
    cin >> h >> w >> K;
    K--;
    p[-1]=1;
    p[-2]=1;
    p[0]=1;
    p[1]=2;
    for(int i=2;i<15;i++){
        p[i] = p[i-1]+p[i-2];
    }
    dp[0][0] = 1;
    for(int i=1;i<=h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<w;k++){
                if(j==k){
                    ll tmp = dp[i-1][k]*p[j-1];
                    tmp %=mod;
                    tmp = tmp*p[w-j-2];
                    tmp %=mod;
                    dp[i][j] +=tmp;
                    dp[i][j] %=mod; 
                }else if(j==k+1){
                    ll tmp = dp[i-1][k]*p[j-2];
                    tmp %=mod;
                    tmp = tmp*p[w-j-2];
                    tmp %=mod;
                    dp[i][j] +=tmp;
                    dp[i][j] %=mod;
                }else if(j==k-1){
                    ll tmp = dp[i-1][k]*p[j-1];
                    tmp %=mod;
                    tmp = tmp*p[w-j-3];
                    tmp %=mod;
                    dp[i][j] +=tmp;
                    dp[i][j] %=mod;
                }
            }
        }
    }
    cout << dp[h][K] << endl;
    return 0;
}

Measured memory_bytes: 888
from collections import Counter

ab = []

for i in range(0, 3):
    ai, bi = [int(_) for _ in input().split()]
    ab.append(ai)
    ab.append(bi)

c = Counter(ab)
lis = sorted(list(c.values()))
if lis[0] == 1 and lis[1] == 1 and lis[2] == 2 and lis[3] == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s; cout<<s.substr(0,3)<<'\n';
}	


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

#define INF 100000000



int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int m = max({a,b,c});
    int n = m*pow(2,k);

    cout << a+b+c-m+n <<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  auto judge=[&](ll x){
    ll cnt=0;
    for (int i = 0; i < n; ++i)
    {
      if(a[i]%x==0) cnt+=a[i]/x-1;
      else cnt+=a[i]/x;
    }
    return cnt<=k;
  };

  ll ng=0;
  ll ok=1e9;
  while(abs(ok-ng)>1)
  {
    ll mid=(ok+ng)/2;
    if(judge(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;

}

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

using namespace std;
const int N=200;
int n,m,l[N][N],u[N][N],L[2][N][N][N],U[2][N][N][N],cur,ans;
char mp[N][N];

void chkmax(int&x,int y){if(x<y)x=y;}
void chkmin(int&x,int y){if(x>y)x=y;}

int main(){
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;++j)
		l[i][j]=mp[i][j]==mp[i][j-1]?l[i][j-1]+1:1,
		u[i][j]=mp[i][j]==mp[i-1][j]?u[i-1][j]+1:1;
	}
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j){
		for(int k=i,mn=m;k<=n;++k){
			if(mp[i][j]!=mp[k][j])break;
			chkmin(mn,l[k][j]);
			L[0][i][j][k]=mn;
		}
		for(int k=j,mn=n;k<=m;++k){
			if(mp[i][j]!=mp[i][k])break;
			chkmin(mn,u[i][k]);
			U[0][i][j][k]=mn;
		}
	}
	for(;;cur^=1,++ans){
		if(L[cur][1][m][n]==m||U[cur][n][1][m]==n)break;
		for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			for(int k=i;k<=n;++k){
				int &tmp = L[cur^1][i][j][k];
				tmp = L[cur][i][j][k] + L[cur][i][j - L[cur][i][j][k]][k];
				int le=i,ri=k-1;
				while(le <= ri){
					int mid = le + ri >>1;
					chkmax(tmp, min(L[cur][i][j][mid] , L[cur][mid+1][j][k]));
					if(L[cur][i][j][mid] > L[cur][mid+1][j][k])le = mid + 1;
					else ri = mid - 1;
				}
			}
			for(int k=j;k<=m;++k){
				int &tmp = U[cur^1][i][j][k];
				tmp = U[cur][i][j][k] + U[cur][i - U[cur][i][j][k]][j][k];
				int le=j,ri=k-1;
				while(le <= ri){
					int mid = le + ri >>1;
					chkmax(tmp, min(U[cur][i][j][mid],U[cur][i][mid+1][k]));
					if(U[cur][i][j][mid] > U[cur][i][mid+1][k])le = mid + 1;
					else ri = mid - 1;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 123136
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int dp[41][1<<18];


int main(){
    int n,x,y,z;
    cin >> n >> x >> y >> z;
    int ng=0;
    ng|=1<<z-1;
    ng|=1<<y+z-1;
    ng|=1<<x+y+z-1;
    int mask=(1<<x+y+z)-1;
    dp[0][0]=1;
    for (int i = 0; i < n; i++) {
        for (int k = 0; k <= mask; k++) {
            for (int j = 1; j <= 10; j++) {
                int nx=((k<<j)|(1<<(j-1)))&mask;
                if((nx&ng)==ng) continue;
                dp[i+1][nx]+=dp[i][k];
                dp[i+1][nx]%=mod;
            }
        }
    }
    LL ans=1;
    for (int i = 0; i < n; i++){
        ans*=10;
        ans%=mod;
    }
    for (int i = 0; i <= mask; i++) {
        ans=(ans+mod-dp[n][i])%mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 40192
#include <algorithm>
#include <cstdio>
int A, B;

int main() {
    scanf(" %d%d", &A, &B);
    if (A > B) std::swap(A, B);
    int D = B - A;
    if (D & 1) {
        puts("IMPOSSIBLE");
    } else {
        printf("%d\n", A + D / 2);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		int[] B = new int[M];
		for(int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < N; i++) {
			int sum = 0;
			for(int j = 0; j < M; j++) {
				int A = sc.nextInt();
				sum += A * B[j];
			}
			if(sum + C > 0) {
				count++;
			}
		}
		System.out.println(count);

	}

}


Measured memory_bytes: 22868
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    V, E = map(int, input().split())
    cost = [[f_inf] * V for _ in range(V)]
    for i in range(V):
        cost[i][i] = 0
    for _ in range(E):
        s, t, d = map(int, input().split())
        cost[s][t] = d

    for k in range(V):
        for i in range(V):
            for j in range(V):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    for i in range(V):
        for j in range(V):
            if i == j and cost[i][j] < 0:
                print("NEGATIVE CYCLE")
                exit()
            if cost[i][j] == f_inf:
                cost[i][j] = "INF"

    for res in cost:
        print(*res)


if __name__ == '__main__':
    resolve()



Measured memory_bytes: 6284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    map<string, ll> mp;
    rep(i, 0, n) {
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll ans = 0;
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (a, b): (Vec<usize>, Vec<usize>) = {
        let (mut a, mut b) = (vec![], vec![]);
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b)
    };

    let P = {
        let mut P = (0..N).map(|i| (a[i], b[i])).collect::<Vec<_>>();
        P.sort();
        P
    };

    let (ans, _) = P.iter().fold((0, 0), |(res, acc), &(x, y)| if res == 0 && acc + y >= K { (x, acc + y) } else { (res, acc + y) });

    println!("{}", ans);
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(all(d), greater<int>());

    ll ans = 1;
    rep(i, n-1){
        if(d[i+1] < d[i]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	rep(i, 3) {
		if (s[i] == t[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;	
}


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

using namespace std;

int main() {
	
	int n, m;
	vector< vector<int> > a;
	vector< vector<int> > b;
	char tmp;

	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		a.resize(n);
		for (int j = 0; j < n; ++j) {
			cin >> tmp;
			if (tmp == '#') {
				a[i].push_back(0);
			}
			else {
				a[i].push_back(1);
			}
		}
	}

	for (int i = 0; i < m; ++i) {
		b.resize(m);
		for (int j = 0; j < m; ++j) {
			cin >> tmp;
			if (tmp == '#') {
				b[i].push_back(0);
			}
			else {
				b[i].push_back(1);
			}
		}
	}

	int f;

	for (int i = 0; i < n-m+1; ++i) {
		for (int j = 0; j < n-m+1; ++j) {
			f = 1;
			for (int k = 0; k < m; ++k) {
				for (int l = 0; l < m; ++l) {
					if (a[i+k][j+l] == b[k][l] ) {
						if (k == m - 1 && l == m - 1 && f == 1) {
							cout << "Yes" << endl;
							return 0;
						}
					}
					else {
						f = 0;
					}
				}
			}
		}
	}

	cout << "No" << endl;

}

Measured memory_bytes: 256
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n;
vector<pll> child[200000];

vector<pll> dat[200000];

vector<pll> u;

ll nowparam;

void back(int now, int parent)
{
	if(child[now].size() == 0)
	{
		dat[now].emplace_back(0, 0);
		return;
	}
	int x=child[now][0].first, y=child[now][1].first;
	ll xd=child[now][0].second, yd=child[now][1].second;
	back(x, now);
	back(y, now);
	if(dat[x].size() > dat[y].size()) swap(x, y), swap(xd, yd);
	int i, j;
	int nowy=0;
	u.clear();
	for(i=0;i<dat[x].size();i++)
	{
		while(nowy < dat[y].size() && dat[y][nowy].first+dat[x][i].second+xd+yd <= nowparam) nowy++;
		if(nowy != 0) u.emplace_back(dat[x][i].first+xd, dat[y][nowy-1].second+yd);
	}
	nowy=0;
	for(i=0;i<dat[x].size();i++)
	{
		while(nowy < dat[y].size() && dat[x][i].first+dat[y][nowy].second+xd+yd > nowparam) nowy++;
		if(nowy != dat[y].size() && dat[x][i].first+dat[y][nowy].second+xd+yd <= nowparam) u.emplace_back(dat[y][nowy].first+yd, dat[x][i].second+xd);
	}
	sort(all(u));
	for(i=0;i<u.size();i++)
	{
		if(!dat[now].size() || dat[now].back().second > u[i].second) dat[now].push_back(u[i]);
	}
}

int param(ll x)
{
	int i, j;
	nowparam=x;
	for(i=0;i<n;i++) dat[i].clear();
	back(0, -1);
	return dat[0].size();
}

int main()
{
	int i, j, k, l;
	cin>>n;
	for(i=0;i<n-1;i++)
	{
		int x, y;
		scanf("%d%d", &x, &y), x--;
		child[x].emplace_back(i+1, y);
	}
	ll low=0, high=1e12, mid;
	param(0);
	while(low <= high)
	{
		mid=(low+high)/2;
		if(param(mid)) high=mid-1;
		else low=mid+1;
	}
	cout<<low<<endl;
	return 0;
}
//*/

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

int main(){
  int N;
  cin >> N;
  vector<int> dp(N+1);
  for (int i=0;i<N+1;i++){
    dp[i]=i;
  }
  for (int i=0;i<N;i++){
    for (int j=1;i+pow(6,j)<=N;j++){
      dp[i+pow(6,j)]=min(dp[i+pow(6,j)],dp[i]+1);
    }
    for (int j=1;i+pow(9,j)<=N;j++){
      dp[i+pow(9,j)]=min(dp[i+pow(9,j)],dp[i]+1);
    }
  }
  cout << dp[N] << endl;
}

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

int main() {
  int n,l,sum = 0;
  cin >> n >> l;
  sum = (l*2 + n -1) * n / 2;
  if (l >= 0) {
    cout << sum - l;
  }
  else if (l+n-1 <= 0) {
    cout << sum - (l+n-1);
  }
  else {cout << sum << endl;}
  
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var input = Console.ReadLine().Split(' ');
            var ans = input.Select((s, i) => new { No = int.Parse(s), Index = i }).OrderBy(x => x.No).Select(x => x.Index + 1);
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


Measured memory_bytes: 33624
#include<iostream>
using namespace std;
#define rep(i,x,n) for(i=(x);i<(n);i++)
#define puts(n) cout << n << endl;
#define put(n) cout << n << " ";
static const int MAX_N=10e5;
long A[MAX_N];
long R[MAX_N],L[MAX_N];
long gcj(long a,long b){if(a<b){long c=a;a=b;b=c;}return (a%b==0?b:gcj(b,a%b));}
long max(long a, long b){return a>b?a:b;}
long ans;
int main(void){
	int N,i;
		cin >> N;
	rep(i,0,N)
		cin >> A[i];
	R[0]=A[0];
	L[N-1]=A[N-1];
	rep(i,1,N){
		R[i]=gcj(R[i-1],A[i]);
		L[N-i-1]=gcj(L[N-i],A[N-i-1]);
	}
	ans=max(R[N-2],L[1]);
	rep(i,1,N-1){
		ans=max(ans,gcj(L[i+1],R[i-1]));
	}
	puts(ans);
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
	double a,b,h,m;
	cin >> a >> b >> h >> m;
	
	double x = (double)abs(h - 11 * m / 60);
	x /= 6;
	if (x >= 1) x = 2 - x;
	x *= PI;
	double ans = (a * a + b * b - 2 * a * b * cos(x));
	ans = pow(ans, 0.5);
	printf("%.10lf", ans);
}



Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    rep(i,d-b)cout << 'U';
    rep(i,c-a)cout << 'R';
    rep(i,d-b)cout << 'D';
    rep(i,c-a)cout << 'L';
    cout << 'L';
    rep(i,d-b+1)cout << 'U';
    rep(i,c-a+1)cout << 'R';
    cout << 'D';
    cout << 'R';
    rep(i,d-b+1)cout << 'D';
    rep(i,c-a+1)cout << 'L';
    cout << 'U';
    cout << endl;
    
    return 0;
}
 
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define rrng(obj) (obj).rbegin(), (obj).rend()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,v.size())i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(v.size())o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pair<char,int> a,pair<char,int> b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
bool f=true;

void Main(){
  int n,m;
  cin>>n>>m;
  cout<<(n+m)*(n+m-1)/2-n*m<<endl;
  // vi a(n);
  // cin>>a;

} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    const ll m = x / d;
    if(m > k){
        x -= d * k;
        cout << x << endl;
        return 0;
    }

    if((k - m) % 2 == 0){
        cout << x - m * d << endl;
    }else{
        cout << abs(x - (m + 1) * d) << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String hundreds = sc.next();
		int count = 0;
		
		for(int i = 0; i < 3; i++) {
			if (hundreds.charAt(i) == '1') {
				count++;
			
			}
		}
		
		System.out.println(count);
	}

}

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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define chmin(a,b) if ((a)>(b)) { a=(b); }
#define chmax(a,b) if ((a)<(b)) { a=(b); }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);
#else
#define debug(...) 
#endif

int main() {
    string s,t;
    cin >> s >> t;

    ll ans = 0;
    rep0(i,s.length()) {
        if (s[i] != t[i]) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3916
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;



int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  intl N,M,K;
  cin >>N>>M>>K;
  vi A(N),B(M);
  Input(A);
  Input(B);
  
  intl tottime=0;
  intl numbooks;
  Rep(i,N){
    tottime += A[i];
    if(tottime > K){
      tottime-=A[i];
      numbooks = i;
      break;
    }
    if (i == N-1){numbooks = N;}
  }
  
  intl j =0;
  intl maxnumbooks = numbooks;
  intl n = numbooks;
  for(intl i = n-1 ; i >= 0; i --){
    while( j < M &&tottime+B[j] <= K){
      tottime += B[j];
      j ++;
      numbooks ++;
    }
    maxnumbooks = max(numbooks,maxnumbooks);
    tottime -= A[i];
    numbooks --;
  }
  while(j < M &&tottime+B[j] <= K){
      tottime += B[j];
      j ++;
      numbooks ++;
    }
  maxnumbooks = max(numbooks,maxnumbooks);
  cout <<maxnumbooks;
}
    

Measured memory_bytes: 6364
<?php
  fscanf(STDIN,'%s',$S);
  $arr = str_split($S);
  $count1=0;
  $count2=0;
  for($i=0;$i<=3;$i++){
  if($arr[$i]=="+"){
    $count1+=1;
  }else{
    $count2+=1;
  }
  }
echo $count1 - $count2;
  

Measured memory_bytes: 3704
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	if(n%2)cout<<n/2<<endl;
	else cout<<n/2-1<<endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    i = 1
    prev = S[0]
    cnt = 1
    while i < len(S):
        if S[i] == prev:
            prev = prev + S[i]
            if i + 1 < len(S):
                prev = S[i] + S[i + 1]
                cnt += 1
                i += 2
            else:
                i += 1
        else:
            prev = S[i]
            cnt += 1
            i += 1

    print(cnt)


if __name__ == '__main__':
    main()


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

int main() {
  int N, K;
  cin >> N >> K ;
  
  int A = 0 ;
  for ( int i=0; i<N; i++){
    int x;
    cin >> x;
    
    if (x<K-x)
      A += x;
    else
      A += K-x;
  }
  
  cout << 2*A << endl;
}


Measured memory_bytes: 3636