akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline

def main():
    s = input()
    len_s = len(s)
    cnt = 0
    for i in range(len_s):
        trial = 0
        for k in range(i,len_s):
            if s[k] in "ACGT":
                trial += 1
            else:
                cnt = max(cnt,trial)
                break
    print(cnt)

if __name__=="__main__":
    main()


Measured memory_bytes: 61908
n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

for a, b in ab:
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)

for c, d in cd:
    block[c-1].append(d-1)
    block[d-1].append(c-1)


class UnionFind:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def find_root(self, x):
        if self.p[x] != x:
            self.p[x] = self.find_root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def unite(self, x, y):
        u = self.find_root(x)
        v = self.find_root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def get_size(self, x):
        return self.size[self.find_root(x)]

uft = UnionFind(n)
for a, b in ab:
    ra = uft.find_root(a - 1)
    rb = uft.find_root(b - 1)
    if ra != rb:
        uft.unite(ra, rb)

ans = []
for i in range(n):
    temp = uft.get_size(i) - 1
    rx = uft.find_root(i)
    for y in friend[i]:
        if uft.find_root(y) == rx:
            temp -= 1
    for y in block[i]:
        if uft.find_root(y) == rx:
            temp -= 1
    ans.append(str(temp))

print(' '.join(ans))

Measured memory_bytes: 95440
# 初期入力
import numpy as np
N,K,Q = (int(x) for x in input().split())
A = [int(input()) for i in range(Q)] 


#
point_i =np.full(N,K) #参加者ごとのポイント　要素数、N   初期値,K

for i in A: #正解した人のポイント加算する
    #point_i = point_i -1
    point_i[i-1] +=1
#print(point_i)

point_i -= Q #全員、全問題数分のポイント減算

for i in point_i:
    if 0 < i:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 17624
import sys

N, M = map(int, input().split())

factor = {}
tmp = 2
while(M // tmp >= 1):
    if(M % tmp != 0):
        if(tmp == 2):
            tmp += 1
        elif(M // tmp < tmp):
            tmp = M
        else:
            tmp += 2
        continue

    M = M // tmp
    factor[tmp] = factor.get(tmp, 0) + 1

if(factor == {}):
    print(1)
    sys.exit()

ans = 1
max_a = 7 + 10 ** 9
max_value = max(list(factor.values()))
aho = {0: 1}
fact = {0: 1}
abc = {}
for i in range(1, max_value + 1):
    # print(i)
    aho[i] = ((aho[i - 1] * (i + N - 1)))
    fact[i] = (fact[i - 1] * i)
    abc[i] = (aho[i] // fact[i]) % max_a


# print(factor)
# print(aho, fact)
for i in factor.values():
    # print(i)
    ans = (ans * abc[i]) % max_a
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
map <pair<string, string>, int> m;
int b;
string t;
bool td[36];
long long u = 0;
string s(bool s, int k)
{
	string ts = "";
	if(s == 0)
	{
		for(int i = k-b; i < k; i++)
		{
			if(td[i] == 1)
			{
				ts += t[i];
			}
		}
	}
	else
	{
		for(int i = k-1; i >= k-b; i--)
		{
			if(td[i] == 0)
			{
				ts += t[i];
			}
		}
	}
	return ts;
}
void f(int p, int k)
{
	if(p == k)
	{
		if(k == b)
		{
			m[make_pair(s(1, k), s(0, k))]++;
		}
		else
		{
			u += m[make_pair(s(0, k), s(1, k))];
		}
		return;
	}
	f(p+1, k);
	td[p] = 1;
	f(p+1, k);
	td[p] = 0;
}
int main()
{
    cin >> b;
    cin >> t;
    f(0, b);
    f(b, 2*b);
    cout << u <<endl;
}



Measured memory_bytes: 91904
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200055;
char s[N],t[N];
int n,m,cnt[N][26];
ll solve(int L,int R,int x)
{
//	cout<<"sol "<<L<<' '<<R<<' '<<x<<endl;
	int l=L,r=R,mid,ret=R;
	while(l<=r){
		mid=(l+r)>>1;
		if(cnt[mid][x]-cnt[L-1][x]) ret=mid,r=mid-1;
		else l=mid+1;
	}
	return ret;
}
int main()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(t+1);
	for(int i=1; i<=n; i++){
		for(int j=0;j<26;j++) cnt[i][j]+=cnt[i-1][j];
		cnt[i][s[i]-'a']++;
	}
	int now=0,ok=1;
	for(int i=1; i<=m; i++){
		if(cnt[n][t[i]-'a']==0){
			ok=0; break;
		}
	}
	if(!ok){
		puts("-1"); return 0;
	}
//	cout<<"hj "<<cnt[3][18]<<endl;
	ll ans=0;
	for(int i=1; i<=m; i++){
		int x=t[i]-'a';
		if(cnt[n][x]-cnt[now][x]==0) ans+=n-now,now=0;
		int res=solve(now+1, n, x);
		ans+=res-now;
		now=res;
//		printf("%lld\n",ans);
	}
	cout<<ans<<endl;
	return 0;
}





Measured memory_bytes: 12672
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let n = read::<usize>();
    let k = read::<i64>();

    let mut w = vec![0; n];    
    let mut v = vec![0; n];    
    for i in 0..n {
        w[i] = read::<i64>();
        v[i] = read::<i64>();
    }

    let mut dp = vec![vec![-1; (k*3) as usize]; n+1];
    for i in 0..n+1 {
        dp[i][0] = 0;
    }
    for i in 0..(k*3) as usize {
        dp[0][i] = 0;
    }
    for i in 0..n {
        for j in 1..(k+1) as usize {
            if w[i] <= j as i64 {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i] as usize]+v[i]);
            } else {
                dp[i+1][j] = max(dp[i+1][j-1], dp[i][j]);
            }
        }
    }
    println!("{}", dp[n][k as usize]);
}

Measured memory_bytes: 418044
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            List<int>[] b = new List<int>[N];
            for (int i = 0; i < N; i++)
            {
                b[i] = new List<int>();
            }

            for (int i = 0; i < M; i++)
            {
                s = Console.ReadLine().Split(' ');
                int f = int.Parse(s[0]) - 1;
                int t = int.Parse(s[1]) - 1;

                b[f].Add(t);
                b[t].Add(f);
            }

            int ans = 0;
            bool con = true;
            while(con)
            {
                con = false;

                for (int i = 0; i < N; i++)
                {
                    if (b[i].Count == 1)
                    {
                        int t = b[i][0];

                        b[i].RemoveAt(0);
                        b[t].Remove(i);

                        con = true;
                        ans++;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    int n; cin>>n;
    int k=0,c,ans=1;
    cin>>c;
    FOR(i,1,n){
        int a; cin>>a;
        if(k==0){
            if(a>c) k=1;
            if(a<c) k=-1;
        }else if(k==1){
            if(a<c){
                ans++;
                k=0;
            }
        }else{
            if(a>c){
                ans++;
                k=0;
            }
        }
        c=a;
    }
    co(ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int b[]=new int[n-1];
		for(int i=0;i<n-1;i++) {
			b[i]=sc.nextInt();
		}
		a[0]=b[0];
		for(int i=1;i<n-1;i++) {
			a[i]=Math.min(b[i-1],b[i]);
		}
		a[n-1]=b[n-2];
		int ans=0;
		for(int i=0;i<n;i++)ans+=a[i];
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    ans = - (10**9 + 7)
    minv = int(input())
    for i in range(1,N):
        r = int(input())
        ans = max(ans, r - minv)
        minv = min(minv, r)
    
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

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

    li n,W;

    cin>>n>>W;

    li w[n],v[n];

    f(i,0,n-1)
    {
        cin>>w[i]>>v[i];
    }

    vi dp(1e5+1,1e18);

    dp[0]=0;

    f(i,0,n-1)
    {
        for(li j=1e5;j>=v[i];j--)
        {
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }

    li ans=-1;

    f(i,1,1e5)
    {
        if(dp[i]<=W)
        {
            ans=i;
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
typedef long long ll;
const ll mod=1000000007;
using namespace std;
ll powmod(ll a,ll b)
{
    ll res=1;
    for(ll i=0; i<b; i++)
    {
        res=res*a%mod;
    }
    return res;
}
int main()
{
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-2*powmod(9,n)+powmod(8,n);
    ll ans1=(ans%mod+mod)%mod;
    cout<<ans1<<endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

struct STree {
  int n;
  vi st;
  vi lazy;
  void build (int u, int l, int r, int val) {
    if (l == r) {
      st[u] = val;
      return;
    }
    int m = (l + r) >> 1;
    build(2 * u, l, m, val);
    build(2 * u + 1, m + 1, r, val);
    st[u] = min(st[2 * u], st[2 * u + 1]);
  }
  STree (int l, int r, int val) {
    n = r;
    st.resize(4 * r);
    lazy.resize(4 * r, INT_MAX);
    build(1, l, r, val);
  }
  void push (int u, int l, int r) {
    if (lazy[u] == INT_MAX) return;
    st[u] = min(st[u], lazy[u]);
    if (l != r) {
      lazy[2 * u] = min(lazy[2 * u], lazy[u]);
      lazy[2 * u + 1] = min(lazy[2 * u + 1], lazy[u]);
    }
    lazy[u] = INT_MAX;
  }
  void update (int u, int l, int r, int L, int R, int val) {
    push(u, l, r);
    if (r < L or R < l) return;
    if (L <= l and r <= R) {
      lazy[u] = val;
      push(u, l, r);
      return;
    }
    int m = (l + r) >> 1;
    update(2 * u, l, m, L, R, val);
    update(2 * u + 1, m + 1, r, L, R, val);
    st[u] = min(st[2 * u], st[2 * u + 1]);
  }
  void update (int l, int r, int val) {
    update(1, 1, n, l, r, val);
  }
  int get (int u, int l, int r, int L, int R) {
    push(u, l, r);
    if (r < L or R < l) return INT_MAX;
    if (L <= l and r <= R) return st[u];
    int m = (l + r) >> 1;
    return min(get(2 * u, l, m, L, R), get(2 * u + 1, m + 1, r, L, R));
  };
  int get (int l, int r) {
    return get(1, 1, n, l, r);
  }
};

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll n, q;
  cin >> n >> q;
  ll black = (n - 2) * (n - 2);
  STree vert(1, n, n);
  STree hor(1, n, n);
  while (q--) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      int c = vert.get(x, x);
      black -= max(0, c - 2);
      hor.update(1, max(1, c - 1), x);
    }
    if (t == 2) {
      int r = hor.get(x, x);
      black -= max(0, r - 2);
      vert.update(1, max(1, r - 1), x);
    }
  }
  cout << black << '\n';
  return (0);
}


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

const int N = 5e5 + 5;
const int inf = 2e9;

int n, m;
vector<pair<int,int>> g[N], new_g[N];
vector<pair<int, pair<int,int>>> edges;	
map<int,int> new_node[N];
int par[N], d[N];
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v, c; cin >> u >> v >> c;
		g[u].push_back({c, v});
		g[v].push_back({c, u});
		edges.push_back({c, {u, v}});
	}
	
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		g[i].push_back({0, 0});
		sort(g[i].begin(), g[i].end());
		
		new_node[i][0] = ++cnt; par[cnt] = i;
		
		for (int j = 1; j < g[i].size(); ++j) {
			if (g[i][j].first != g[i][j - 1].first) {
				new_node[i][g[i][j].first] = ++cnt; par[cnt] = i;
			}
		}
	}
	
	for (auto e : edges) {
		int c = e.first, u = e.second.first, v = e.second.second;
		new_g[new_node[u][c]].push_back({new_node[v][c], 0});
		new_g[new_node[v][c]].push_back({new_node[u][c], 0});
		new_g[new_node[u][0]].push_back({new_node[u][c], 1});
		new_g[new_node[u][c]].push_back({new_node[u][0], 1});
		new_g[new_node[v][0]].push_back({new_node[v][c], 1});
		new_g[new_node[v][c]].push_back({new_node[v][0], 1});
	}
	
	for (int i = 1; i <= cnt; ++i) d[i] = inf;
	for (auto e : new_node[1]) {
		d[e.second] = 1;
		pq.push({1, e.second});
	}
	
	while (!pq.empty()) {
		auto u = pq.top(); pq.pop();
		if (u.first != d[u.second]);
		if (par[u.second] == n) return cout << (u.first + 1) / 2 << '\n',0;
		
		for (auto v : new_g[u.second]) {
			if (d[v.first] > u.first + v.second) {
				d[v.first] = u.first + v.second;
				pq.push({d[v.first], v.first});
			}
		}
	}
	cout << -1 << '\n';
}

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

#define PB push_back
#define MP make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;

const int max_n = 100111, inf = 1000111222;


int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    int n;
    cin >> n;
    if (n < 1200) {
        cout << "ABC";
        return 0;
    }
    if (n < 2800) {
        cout << "ARC";
        return 0;
    }
    cout << "AGC";
    return 0;
}


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

typedef unsigned long long ull;
const int P = 1000000007;

void binarize(int n, vector<int> &bi){
	int amari;
	while(n!=0){
		amari = n%2;
		bi.push_back(amari);
		n=(n-amari)/2;
	}
	return;
}

int  main(){
	int n,m;
	cin >> m >> n;
	vector<int> bi;
	binarize(n,bi);
	int s=bi.size();

	vector<ull> PL(s);
	PL[0]=m%P;
	for(int i=1;i<s;i++){
		PL[i]=(PL[i-1]*PL[i-1])%P;
	}

	ull product=1;
	for (int i=0;i<s;i++){
		if(bi[i]){
			product = (product*PL[i])%P;
		}
	}
	cout << product <<endl;
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>

int main() {
  long N;

  std::cin >> N;

  int ans=0;

  if (N==10 || N==100 ||N==1000 ||N==10000 || N==100000) {
    ans = 10;
  } else {
    for (int i=0; i<5; i++) {
      ans += N%10;
      N /=10;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


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

signed main() {
  int N, H;
  cin >> N >> H;
  
  vector<int> A(N);
  vector<int> B(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i) >> B.at(i);
  
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( B.at(i) < A.back() ) break;
    if( H <= 0 ) break;
    else{
      H -= B.at(i);
      ans++;
    }
  }
  
  if( H > 0 ){
    ans += ( H + A.back() - 1 ) / A.back();
  }
  cout << ans << endl;
    
}
  


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#define LL long long
#define MOD 1000000007
using namespace std;

int n, arr[105];

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++ ) scanf("%d",&arr[i]);
	sort(arr,arr+n);
	printf("%d\n",arr[n-1]-arr[0]);
	return 0;
}


Measured memory_bytes: 128
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])
#print(pl1,pl0,pl_1,draw)
if(pl1>=draw):
  print(draw)
elif(pl1+pl0>=draw):
  print(pl1)
else:
  #all_card=pl1+pl0+pl_1
  #print(all_card)
  draw_pl_1=draw-pl1-pl0
  #print(draw_pl_1)
  print(pl1-draw_pl_1)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n,k;
    cin>>n>>k;
    V<int> h(n);
    cinf(n,h);
    sort(all(h));
    int ans=int(1e9);
    rep(i,n-k+1){
        chmin(ans,h[k-1+i]-h[i]);
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3728
s = input()
mod = 1000000007
dp = [1, 0, 0, 0]
for c in s:
    newdp = [n for n in dp]
    if c == 'A':
        newdp[1] = (newdp[1] + dp[0]) % mod
    if c == 'B':
        newdp[2] = (newdp[2] + dp[1]) % mod
    if c == 'C':
        newdp[3] = (newdp[3] + dp[2]) % mod
    if c == '?':
        newdp[0] = (newdp[0] * 3) % mod
        newdp[1] = (newdp[1] * 3 + dp[0]) % mod
        newdp[2] = (newdp[2] * 3 + dp[1]) % mod
        newdp[3] = (newdp[3] * 3 + dp[2]) % mod
    dp = newdp
print(dp[3])


Measured memory_bytes: 42604
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;

int n;
vector<int> vc[1000];

int main() {
	scanf("%d",&n);
	n<<=1;
	//printf("n=%d\n",n);
	int m=0;
	for(int i=1;i<=n;i++) {
		if(n%i==0) {
			if(i>=n/i) break;
			if(n/i-i==1) {
				m=n/i;break;
			}
		}
	}
	if(m==0) {
		printf("No\n");
		return 0;
	}

	printf("Yes\n");
	int x=0;
	for(int i=0;i<m;i++) {
		vc[i].resize(m-1);
	}
	for(int i=0;i<m-1;i++) {
		for(int j=i;j<m-1;j++) {
			x++;
			vc[i][j]=x;
		}
	}
	x=0;
	for(int i=0;i<m-1;i++) {
		for(int j=i+1;j<m;j++) {
			x++;
			vc[j][i]=x;
		}
	}
	printf("%d\n",m);
	for(int i=0;i<m;i++) {
		printf("%d",m-1);
		for(int j=0;j<m-1;j++) {
			printf(" %d",vc[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 2176
def calc(a, b):
    if a == b:
        return 1
    else:
        return 0


S = input()
S1, S2, S3 = S[0], S[1], S[2]
S = input()
T1, T2, T3 = S[0], S[1], S[2]

print(calc(S1, T1) + calc(S2, T2) + calc(S3, T3))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mxn 200005

using namespace std;
typedef long long ll;

int N, acc[mxn];


int main(){
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    cin >> N;
    int a;
    for (int i = 2; i <= N; i++){
        cin >> a;
        acc[a]++;
    }
    for (int i = 1; i <= N; i++)
        cout << acc[i] << "\n";

    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<tuple<int,int,int> > bye, bys;
	int n, q; cin >> n >> q;
	for(int i = 0; i < n; i++){
		int s, t, x; cin >> s >> t >> x;
		t--;
		bye.push_back(make_tuple(s - x, t - x, x));
		bys.push_back(make_tuple(t - x, s - x, x));
	}
	sort(bye.begin(), bye.end());
	sort(bys.begin(), bys.end());
	multiset<int> now;
	int add = 0, rem = 0;
	for(int i = 0; i < q; i++){
		int d; cin >> d;
		while(add < n){
			int s, t, x; tie(s, t, x) = bye[add];
			if(s <= d){
				now.insert(x);
				add++;
			} else {
				break;
			}
		}
		while(rem < n){
			int s, t, x; tie(t, s, x) = bys[rem];
			if(t < d){
				now.erase(now.find(x));
				rem++;
			} else {
				break;
			}
		}
		if(now.empty()) cout << -1 << endl;
		else cout << *(now.begin()) << endl;
	}
	return 0;
}


Measured memory_bytes: 15268
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

i64 dh[4] = {-1, 1, 0, 0}, dw[4] = {0, 0, -1, 1};

int main()
{
  i64 H, W, Ch, Cw, Dh, Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  vector<string> S(H);
  for (i64 i = 0; i < H; i++)
    cin >> S[i];
  vector<vector<i64>> dis(H, vector<i64>(W, 1e9));
  deque<pair<i64, i64>> que;
  dis[Ch][Cw] = 0;
  que.push_back({Ch, Cw});
  while (que.size())
  {
    pair<i64, i64> p = que.front();
    que.pop_front();
    for (i64 i = 0; i < 4; i++)
    {
      i64 ddh = p.first + dh[i], ddw = p.second + dw[i];
      if (ddh < 0 || H <= ddh || ddw < 0 || W <= ddw || S[ddh][ddw] == '#' || dis[ddh][ddw] <= dis[p.first][p.second])
        continue;
      dis[ddh][ddw] = dis[p.first][p.second];
      que.push_front({ddh, ddw});
    }
    for (i64 i = -2; i < 3; i++)
      for (i64 j = -2; j < 3; j++)
      {
        i64 ddh = p.first + i, ddw = p.second + j;
        if (ddh < 0 || H <= ddh || ddw < 0 || W <= ddw || S[ddh][ddw] == '#' || dis[ddh][ddw] <= dis[p.first][p.second] + 1)
          continue;
        dis[ddh][ddw] = dis[p.first][p.second] + 1;
        que.push_back({ddh, ddw});
      }
  }
  cout << (dis[Dh][Dw] == 1e9 ? -1 : dis[Dh][Dw]) << endl;
  return 0;
}


Measured memory_bytes: 13552
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if (b*c>=a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;	
} 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,nn,wa = 0;
	cin >> n;
	nn = n;
	for(int i = 0;i < 9;i++){
		wa += nn % 10;
		nn /= 10;
	}
	if(n % wa == 0) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int i;
bool f;
string s;
int main(){
	cin>>s;
	for(;i<s.size();++i)if(s[i]=='C')break;
	for(;i<s.size();++i)if(s[i]=='F')f=true;
	cout<<(f?"Yes\n":"No\n");
}

Measured memory_bytes: 256
S = input()
ans = 0
temp = 0
for i in range(len(S)):
    if S[i] == "A" or S[i] == "T" or S[i] == "C" or S[i] == "G":
        temp += 1
        ans = max(temp, ans)
    else:
        temp = 0
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  n %= 500;
  if(n <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

#define int long long

signed main(){
  int n;
  cin >> n;
  int sum = 0;
  vector<int> a;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    sum += tmp;
    a.push_back(tmp);
  }
  int ans = 0;
  for(auto& A : a){
    ans += A * (sum - A);
  }
  ans /= 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N) {
    string ans = ":(";

    ll in_tax;

    for (ll n = 1; n <= N; n++) {
        in_tax = int(n * 1.08);
        if (in_tax == N) {
            ans = to_string(n);
        }
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 3644
#include <stdio.h>
int main(){
	int n,i,j,c[1002],t;
	long ans=1;
	scanf("%d",&n);
	for(i=1;i<=1000;i++)
	c[i]=0;
	for(i=1;i<=n;i++){
		t=i;
		j=2;
		while(t!=1){
			if(t%j==0){
				c[j]++;
				t=t/j;
				j=1;
			}
			j++;
		}
	}
	for(i=1;i<=n;i++){
    	ans=ans*(c[i]+1);
    	ans=ans%1000000007;
    }
    printf("%d",ans);
    return 0;
 }

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int ans = 1LL * (n-1) * n / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	vector<int> h(n);
	for (int& h_s : h) {
		cin >> h_s;
	}
	int max = 0;
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (h[i] >= max) {
			count++;
			max = h[i];
		}
	}
	cout << count;
}

Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
s=input()
ans=[]
current=n
while current>0:
  for i in range(m):
    if current-(m-i)<0:
      continue
    if s[current-(m-i)]=='0':
      current-=(m-i)
      ans.append(str(m-i))
      break
    if i==m-1:
      print(-1)
      sys.exit()
ans.reverse()
print(' '.join(ans))

Measured memory_bytes: 73356
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if lst1[i][j] %2 == 1:
            ans.append([i,j,i,j+1])
            lst1[i][j+1] += 1

for i in range(h-1):
    if lst1[i][-1] %2 == 1:
        ans.append([i,w-1,i+1,w-1])
        lst1[i+1][-1] += 1

print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1) 

Measured memory_bytes: 68956
using System;

class AtCoder
{
    static void Main()
    {
        string[] s;

        s = NextS();
        int n = int.Parse(s[0]);
        s = NextS();
        int h = int.Parse(s[0]);
        s = NextS();
        int w = int.Parse(s[0]);
        Console.WriteLine((n - h + 1) * (n - w + 1));
    }

    static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int N, M;
    cin >> N >> M;
    cout << ( N*(N-1) + M*(M-1) ) / 2 << endl;
}

Measured memory_bytes: 256
N , M = map(int, input().split())

a = [0 for _ in range(M)]

for _ in range(N):
    A = list(map(int, input().split()))
    A.pop(0)
    for i in range(len(A)):
        a[A[i]-1] += 1

ans = 0
for i in range(M):
    if a[i] == N:
        ans += 1
print(ans)


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  cout << w*h/2 << " " << (w/2==x && h/2==y) << endl;

}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    if (a[i] > b[i]) ans += b[i];
    else {
      ans += a[i];
      b[i] -= a[i];
      if (a[i+1] > b[i]) {
        ans += b[i];
        a[i+1] -= b[i];
      } else {
        ans += a[i+1];
        a[i+1] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
  using namespace std;
  typedef long long int ll;
  #define mod 1000000007
  #define all(v)  v.begin(),v.end()
  #define pb push_back
  #define size(v)  (int) v.size()
  #define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
  ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
  ll inv(ll a){return power_mod(a,mod-2);}
  ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}
  #define N 100005
  vector<int> adj[N];
  int vis[N];
  int dis[N];
  int ans=0;
  void dfs(int curr)
  {

      vis[curr]=1;
  	  
  	  for(auto i: adj[curr])
  	  {
           if(!vis[i])
           {
           	  dfs(i);
           }

           dis[curr]=max(dis[curr],1+dis[i]);
           ans=max(ans,dis[curr]);
  	  }

      
  }
  int main()
  {
     

        int n,m;
        cin>>n>>m;
        memset(vis,0,sizeof(vis));
        memset(dis,0,sizeof(dis));
        for(int i=1;i<=m;i++)
        {
        	 int u,v;
        	 cin>>u>>v;
        	 adj[u].pb(v);
        }

        for(int i=1;i<=n;i++)
        {
        	 if(!vis[i])
        	 dfs(i);

        	// cout<<dis[i]<< " ";  
        }
       //cout<<"\n";
        cout<<ans<<endl;
  }




Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		vi v(2001);
		int ans=0;
		rer(i,0,min(1000,n)){
			rer(j,0,min(1000,n)){
				v[i+j]++;
			}
		}
		/*sort(all(v));
		rep(i,0,v.size()){
			ans+=upper_bound(all(v),n-v[i])-lower_bound(all(v),n-v[i]);
		}*/
		/*rer(i,0,min(1000,n)){
			rer(j,0,min(1000,n)){
				if((n-i-j)<0) continue;
				ans+=upper_bound(all(v),n-i-j)-lower_bound(all(v),n-i-j);
			}
		}*/
		rer(i,0,v.size()){
			rer(j,0,v.size()){
				if(i+j==n) ans+=(v[i]*v[j]);
			}
		}
		o(ans);
	}
}

Measured memory_bytes: 1204
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

res = 0

t_0 = T[0]
c = C

for t in T:
    if c == 0 or t - t_0 > K:
        res += 1
        t_0 = t
        c = C - 1
    else:
        c -= 1
else:
    if c != C:
        res += 1

print(res)


Measured memory_bytes: 7444
#create date: 2020-06-29 13:18

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    v = na()
    c = na()
    ans = 0
    for vi, ci in zip(v, c):
        ans += max(0, vi-ci)
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N; cin >> N;
  bool a[N]; rep(i,N) cin >> a[i];
  bool ball[N];
  for (int i=N; i>0; i--) {
    int tmp = false;
    for (int j=2; i*j<=N; j++) tmp ^= ball[i*j-1];
    ball[i-1] = a[i-1]^tmp;
  }
  int sum = 0; rep(i,N) if (ball[i]) sum++;
  cout << sum << endl;
  if (sum!=0) rep(i,N) if (ball[i]) cout << i+1 << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<pair<string, pair<int, int>>> data(N);
	string city;
	int rank;
	for (int i = 0; i < N; i++) {
		cin >> city >> rank;
		data[i] = (make_pair(city, make_pair(rank * -1, i + 1)));
	}

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

	for (const auto &elem : data) {

		cout << elem.second.second << "\n";

	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int[] chars = new int[26];
      
      for (char c: s.toCharArray()) {
      	chars[c - 'a']++;
      }
      
      for (int i = 0; i < 26; i++) {
      	if (chars[i] % 2 == 1) {
        	System.out.println("No");
          	System.exit(0);
        }
      }
      System.out.println("Yes");
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {

	int a, b, c;
	cin >> a >> b >> c;

	int cnt = 0;

	if (a == b) cnt++;
	if (b == c)cnt++;
	if (a == c)cnt++;

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


	return 0;

}




Measured memory_bytes: 3572
from collections import deque

N, M = map(int, input().split())
edge = [map(int, input().split()) for _ in range(M)]

g = [[] for _ in range(N + 1)]
for a, b in edge:
    g[a].append(b)
    g[b].append(a)

ans = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in g[i]:
        if ans[j] == -1:
            ans[j] = i
            q.append(j)
print('Yes')
for i in ans[2:]:
    print(i)


Measured memory_bytes: 105616
n=int(input())
c=[0]*(n-1);s=[0]*(n-1);f=[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
  
for i in range(n):
  ans=0
  for j in range(i,n-1):
    if ans <= s[j] :
      ans = s[j] + c[j]
    elif ans%f[j] == 0:
      ans += c[j]
    else:
      ans += c[j] + (f[j]-ans)%f[j]
  print(ans)
    


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}


void init()
{
	vector<int> a;
	int sum = 0;
	int N;
	cin >> N;
	rep(i, N) {
		int t;
		cin >> t;
		sum += t;
		a.PB(t);
	}
	sort(all(a));
	sum -= a.back();
	if (a.back() < sum) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

void solve()
{
}




Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	long long X, en = 100, nen = 0;

	cin >> X;

	while (true){

		en *= 1.01;
		nen++;
		if (en >= X) {
			break;
		}
		
	}
	cout << nen << endl;

	return 0;
}

Measured memory_bytes: 3632
inputs = [int(x) for x in input().split()]
n, k = inputs[0], inputs[1]
ls = [int(x) for x in input().split()]
s = sum(ls)

# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56
divisors = []
for i in range(1, int(s ** 0.5) + 1):
  if s % i == 0:
    divisors.append(i)
    if i != s // i:
      divisors.append(s // i)

divisors.sort(reverse=True)
ans = 1
for d in divisors:
  mods = sorted([l % d for l in ls if l % d != 0])
  opcnt = 0
  is_success = False
  # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))
  while True:
    if opcnt > k or len(mods) == 1:
      # print("opcnt: {}".format(opcnt))
      is_success = False
      break

    if len(mods) == 0:
      is_success = True
      ans = d
      # print("ans: {}, opcnt: {}".format(ans, opcnt))
      break

    if mods[0] + mods[-1] < d:
      mods[-1] += mods[0]
      opcnt += mods[0]
      mods.pop(0)
    elif mods[0] + mods[-1] == d:
      opcnt += mods[0]
      mods.pop(0)
      mods.pop(-1)
    else:
      opcnt += (d - mods[-1])
      mods[0] -= (d - mods[-1])
      mods.pop(-1)
    # print("{}: {}".format(d, ", ".join([str(m) for m in mods])))


  if is_success:
    break

print(ans)




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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a>9 || b>9) cout << -1  << endl;
    else cout << a*b << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

vector<vector<int>> E;

void dfs(int l,int r,int level){
	int x = (r-l)/2;
	
	for(int i=l;i<l+x;i++){
		for(int j=l+x;j<r;j++){
			E[i][j] = level;
			E[j][i] = level;
		}
	}
	
	if(r-l<=2)return;
	
	dfs(l,l+x,level+1);
	dfs(l+x,r,level+1);
	
}

int main(){
	
	int N;
	cin>>N;
	
	for(int i=0;i<N;i++){
		E.push_back(vector<int>(N,0));
	}
	
	dfs(0,N,1);
	
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			if(j!=i+1)cout<<' ';
			cout<<E[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1536
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

vector<vector<ll> > table;
vector<P> roads;
vector<P> qs;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  cout << (N - A) % B << endl;

  return 0;
}


Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N,A,B = list(map(int,input().split()))
v = list(map(int,input().split()))
v.sort(reverse=True)

data = []
cnt = 0
ans = 0
for i in v:
  data.append(i)
  cnt += 1
  if cnt == A:
    vnum = v.count(i)
    datanum = data.count(i)
    if cnt == datanum:
      for j in range(A,min(B, vnum)+1):
        #print(vnum, j)
        ans += cmb(vnum, j)
      break
    else:
      ans = cmb(vnum, datanum)
      #print(vnum,datanum)
      break
print(sum(data)/len(data))
print(ans)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, t;
	cin >>n >>t;
	vector<pii> vp(n);
	rep(i, n) cin >>vp[i].first >>vp[i].second;
	sort(all(vp));
	VL dp(t+5);
	ll ans = 0;
	rep(i, n) repr(j, t-1, 0) {
		int nj = min(j + vp[i].first, t+2);
		dp[nj] = max(dp[nj], dp[j]+vp[i].second);
		ans = max(ans, dp[nj]);
	}

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


Measured memory_bytes: 384
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int m,a[100000];
    for(int i=0;i<100000;i++)
    {
        a[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>m;
        if(m<=100000)a[m-1]++;
        else cnt++;
    }
    for(int i=0;i<100000;i++)
    {
        if(a[i]>i+1)cnt+=a[i]-(i+1);
        else if(a[i]<i+1)cnt+=a[i];
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) {if(a<b) {a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b) {a=b;return 1;} return 0;}
const ll MOD = 1000000007LL;
const ll INF = 1LL<<60;

int main() {
    int N, M, a;
    cin >> N >> M;
    set<int> A;
    for ( int i = 0; i < M; i++ ) {
        cin >> a;
        A.insert(a);
    }
    vector<ll> num(N+1,0);
    num[0] = 1;
    for ( int i = 1; i <= N; i++ ) {
        if ( A.find(i) != A.end() ) continue;
        num[i] = (num[i] + num[i-1]) % MOD;
        if ( i >= 2 ) {
            num[i] = (num[i] + num[i-2]) % MOD;
        }
    }
    cout << num[N] << '\n';
    return 0;
}

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

int main()
{
    string s,t;
    cin >> s >> t;
    int ls = s.length(), lt = t.length(),m = 0;
    for(int i = 0; i+lt <= ls; i++){
    	int maxn = 0;
    	for(int j = 0; j < lt; j++){
    		if(s[i+j] == t[j])
    			maxn++;
		}
		m = max(m,maxn);
	}
	cout << lt-m << endl;
}

Measured memory_bytes: 3636
v, e = map(int, input().split())

adj_mat = [[float("inf")] * v for j in range(v)]
dist = [[float("inf")] * v for j in range(v)]

for i in range(e):
    s, t, d = map(int, input().split())
    # adj_mat[s][t] = d
    dist[s][t] = d

for i in range(v):
    dist[i][i] = 0

for k in range(v):
    for i in range(v):
        for j in range(v):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

for i in range(v):
    if dist[i][i] < 0:
        print("NEGATIVE CYCLE")
        exit()

for i in range(v):
    for j in range(v):
        if dist[i][j] == float("inf"):
            print("INF", end="")
        else:
            print("%d" % (dist[i][j]), end="")

        if j < v - 1:
            print(" ", end="")
    print()



Measured memory_bytes: 6896
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,k;
 cin>>n>>k;
 int a[n];
 for(int i=0;i<n;i++)
 cin>>a[i];
int dp[n]={0};
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++)
{
  dp[i]=INT_MAX;
  for(int j=1;j<=k&&j<=i;j++)
  dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
}
cout<<dp[n-1];
}






Measured memory_bytes: 1024
//CountingSort計算ソート
//なぜかTLEになる
using System;
using System.Linq;

namespace tst
{
    class Program
    {
        public static int n = 0;
        public static void Count(int[] A, int[] B, int k)
        {
            int[] C = new int[k + 1];
            //Ai以下の要素の数をCに保存
            //A=[2,5,1,3,2,3,0]をC=[1,1,2,2,0,1]
            foreach (int x in A)
            {
                C[x]++;
            }
            //累積和//C=[1,2,4,6,0,7]
            for (int i = 1; i <= k; i++)
            {
                C[i] += C[i - 1];
            }
            for (int i = n - 1; i >= 0; i--)
            {
                B[C[A[i]] - 1] = A[i];
                C[A[i]]--;
            }
        }
        public static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] A = new int[n];
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                A[i] = int.Parse(In[i]);
                if (A[i] >= max) max = A[i];
            }
            int[] B = new int[n];
            Count(A, B, max);

            /*for (int i = 0; i < n - 1; i++)
            {
                Console.Write("{0} ", B[i]);
            }
            Console.WriteLine(B[n - 1]);
            */
            Console.WriteLine(string.Join(" ", Array.ConvertAll(B, b => b.ToString())));
        }

    }
}


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

int main(void){
    int n = 0, a = 0;

    scanf("%d%d", &n, &a);

    if(n % 500 <= a){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;

} 


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, s= 2;
    cin>> n;

    if(n<=2)
    {
        cout << 4<< '\n';
        return 0;
    }

    while (n>1)
    {
        n= (n&1? (n*3)+1 : n/2);
        s++;
    }


    cout << s;
    nl;

    return 0;
}


Measured memory_bytes: 3656