akhauriyash/Code-Regression huggingface dataset:
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
INF = 10010001001
way = [[0, 1], [0, -1], [1, 0], [-1, 0]]

ans = 0
for sy in range(h):
    for sx in range(w):
        dist = [[INF] * w for _ in range(h)]
        dist[sy][sx] = 0
        if S[sy][sx] == '#':
            continue
        q = deque()
        q.append((sy, sx))
        while q:
            y, x = q.popleft()
            for dy, dx in way:
                ny, nx = y + dy, x + dx
                if 0 <= ny <= h - 1 and 0 <= nx <= w - 1 and S[ny][nx] == '.' and dist[ny][nx] == INF:
                    dist[ny][nx] = dist[y][x] + 1
                    ans = max(ans, dist[y][x] + 1)
                    q.append((ny, nx))
print(ans)

Measured memory_bytes: 45532
n = int(input())

li = []

for i in range(n):
    s,p = map(str, input().split())
    p = int(p)
    li.append((s,p,i))

li.sort(key = lambda x:x[1])
li.sort(key = lambda x:x[0],reverse = True)
li = li[::-1]

for i in range(n):
    print(li[i][2] + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int dfs(int n,int x,int m,vector<int> a,vector<int> b,vector<int> &c);//連結だったら1を返す

int main(){
	int n,m;
	cin>>n>>m;
	if(m==1){
		cout<<1<<endl;
	}
	vector<int> a0(m),b0(m),a(m-1),b(m-1),c(n);
	rep(i,m){
		cin>>a0[i]>>b0[i];
		a0[i]--;
		b0[i]--;
	}
	
	
	int ans=0;//連結な数

	rep(i,m){
		rep(j,m){
			if(j<i){
				a[j]=a0[j];
				b[j]=b0[j];
			}else if(i<j){
				a[j-1]=a0[j];
				b[j-1]=b0[j];
			}
		}
		rep(j,n){
			c[j]=0;
		}
		c[0]=1;
		dfs(n,0,m-1,a,b,c);
		rep(j,n){
			if(c[j]==0) break;
			if(j==n-1) ans++;
		}
	}
		
	cout<<m-ans<<endl;
}

int dfs(int n,int x,int m,vector<int> a,vector<int> b,vector<int> &c){
	
	rep(i,m){
		if(a[i]==x && c[b[i]]==0){
			c[b[i]]=1;
			dfs(n,b[i],m,a,b,c);
		}
		if(b[i]==x && c[a[i]]==0){
			c[a[i]]=1;
			dfs(n,a[i],m,a,b,c);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y;
  cin>>x>>y;
  vector<int>A={1,3,1,2,1,2,1,1,2,1,2,1};
  if(A[x-1]==A[y-1])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
const int MAXN = 1e6 + 10;

int n;
int deg[MAXN];
struct Edge {
  int v, next;
}edge[MAXN << 1];
int head[MAXN], tail;
void insert(int u, int v) {
  edge[++tail] = (Edge) {v, head[u]}; head[u] = tail;
}
int bitcount(int x) {
  return x ? bitcount(x >> 1) + (x & 1) : 0;
}
namespace solver1 {
  int dfs(int u, int fa, bool &need) {
    int ans = 0, cnt = 0, son = 0;

    for (int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].v;
      if (v == fa) continue;
      bool f = 0;
      int val = dfs(v, u, f);
      ans += val;
      cnt += val == 0;
      son++;
    }
    need = 0;
    return ans + std::max(cnt - 1, 0);
    
  }
  void main() {
    //int ans = 0;
    for (int i = 1; i <= n; i++) {
      
      if (deg[i] > 2) {
        bool t = 0;
        printf("%d\n", dfs(i, 0, t));
        return;
      }
      
      
    }
    
    //printf("%d\n", ans - 1);
    
  }
}
namespace solver2 {
  int mp[25][25];
  void main() {
    memset(mp, 63, sizeof mp);
    for (int i = 1; i <= n; i++) mp[i][i] = 0;
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u++, v++;
      mp[u][v] = mp[v][u] = 1;
    }
    
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          mp[i][j] = std::min(mp[i][k] + mp[k][j], mp[i][j]);
        }
      }
    }
    
    int ans = 1e9;
    for (int mask = 0; mask < (1 << n); mask++) {
      std::set< std::vector <int> > s;
      bool flag = 1;
      for (int j = 1; j <= n; j++) {
        std::vector <int> v;
        for (int k = 1; k <= n; k++) {
          if (mask & (1 << (k - 1))) {
            v.push_back(mp[j][k]);
          }
        }
        if (s.count(v)) {
          flag = 0;
          break;
        }
        s.insert(v);
      }
      if (flag) {
        int v = bitcount(mask);
        if (v < ans) {
          ans = v;
          //t = mask;
        }
      }
    }
    printf("%d\n", ans);
  }
    

}
int main() {
  scanf("%d", &n);
  
  if (n <= 12) {
    solver2::main();
  } else {
  
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u++,v++;
      deg[u]++;
      deg[v]++;
      insert(u, v);
      insert(v, u);
    }
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
      flag &= deg[i] <= 2;
    }

    if (flag) {
      puts("1");
      
    } else {

      solver1::main();
    }
  }
}


Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

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

    vector<int> K(M,0);

    for(int i = 0; i < N; i++){
        int k;
        cin >> k;

        for(int j = 0; j < k; j++){
            int a;
            cin >> a;

            K[a-1]++;
        }
    }

    int sum = 0;

    for(int i = 0; i < M; i++){
        if(K[i] == N){
            sum++;
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
idx = {}
while True:
    try:
        data = raw_input().split();
        if data[0] in idx:
            idx[data[0]].append(int(data[1]))
        else:
            idx[data[0]] = [int(data[1])]
    except (EOFError):
        break

for word in sorted(list(idx)):
    print word
    for page in sorted(idx[word]):
        print page,
    print

Measured memory_bytes: 4232
#include <stdio.h>

#define MAX 16

int main(void){
	int a[MAX][MAX];
	int n;
	
	while (scanf("%d", &n), n){
		for (int i=0; i<=n; i++) a[n][i] = a[i][n] = 0;
		for (int i=0; i<n; i++){
			for (int j=0; j<n; j++){
				scanf("%d", &a[i][j]);
				a[i][n] += a[i][j];
				a[n][j] += a[i][j];
				a[n][n] += a[i][j];
			}
		}
		for (int i=0; i<=n; i++){
			for (int j=0; j<=n; j++){
				printf("%5d",a[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
using P = pair<string, int>;
using ll = long long;
ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a,b);
    cout << a * b / g << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
    char ch = getchar();
    x = 0;
    t f = 1;
    while (ch < '0' || ch > '9')
        f = (ch == '-' ? -1 : f), ch = getchar();
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}
//---------------https://lunatic.blog.csdn.net/-------------------//
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 100005
#define fil(a, n) rep(0, n, i) read(a[i])
ll power(ll a, ll b, ll p)
{
    ll ans = 1 % p;
    for (; b; b >>= 1)
    {
        if (b & 1)
            ans = ans * a % p;
        a = a * a % p;
    }
    return ans;
}
long long mm[500000];
void init(ll n, ll k)
{
    mm[1] = 1;
    for (ll i = 2; i <= n; i++)
    {
        mm[i] = ((mm[i - 1] * (k + i - 1)) % MOD * power(i - 1, MOD - 2, MOD)) % MOD;
        //cout<<mm[i]<<endl;
    }
}
ll a[N];
int main()
{
    int n, k;
    read(n), read(k);
    fil(a, n);
    sort(a, a + n);
    init(n-k+2, k - 1);
    long long sum = 0;
    rrep(n - 1, k - 2, i)
        sum = (sum + (mm[i - k + 2] * (a[i] - a[n - i - 1]) % MOD) % MOD) % MOD;
    wl((sum+MOD)%MOD);
    P;
}

Measured memory_bytes: 1408
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # 価値V - コストC 
    D = [V[i] - C[i] for i in range(N)]
    # V - C > 0のフィルタ
    F = [d for d in D if d > 0]

    if len(F) == 0:
        print(0)
    else:
        print(sum(F))

if __name__ == "__main__":
    main()

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

int main(){

	int r, c;
	int num[101][101] = {0} ;

	cin >> r >> c;

	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> num[i][j];
			//横軸の合計値の計算
			num[i][c] += num[i][j];
			//縦軸の合計値の計算
			num[r][j] += num[i][j];
		}
		//縦横の合計の値の計算
		num[r][c] += num[i][c];
	}

	for(int i = 0; i <= r; i++){
		for(int j = 0; j <= c; j++){
			cout << num[i][j] << " \n"[j == c];
		}
	}

	

	return 0;
}


Measured memory_bytes: 3144
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]

satisfied = 0

for i, a in enumerate(A_list):
  point = B_list[a-1]
  satisfied += point
  
  if i != 0:
    previous = A_list[i-1]
    
    if previous == a-1:
      satisfied += C_list[previous-1]

print(satisfied)

Measured memory_bytes: 3064
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> a){

    vector<int> cnt(n, 0);
    for(int i = 0; i < n - 1; ++i)
        ++cnt[a[i] - 1];
    for(int i = 0; i < n; ++i)
        cout << cnt[i] << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5656
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
//#define MOD 1000000007
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

struct edge{ll to, cost;};
struct graph{
ll V;
vector<vector<edge> > G;
vector<ll> d;
graph(ll n){
    init(n);
}
void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
    d[i] = INF;
    }
}
void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
}
void dijkstra(ll s){
    rep(i,V){
    d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
    P p = que.top(); que.pop();
    ll v = p.second;
    if(d[v]<p.first) continue;
    for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
        d[e.to] = d[v]+e.cost;
        que.push(P(d[e.to],e.to));
        }
    }
    }
}
};

int main()
{
    ll N, M;
    cin >> N >> M;
    graph g(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;b--;
        g.add_edge(a, b, 1);
    }
    g.dijkstra(0);
    if (g.d[N-1] <= 2) {
        print("POSSIBLE");
    } else {
        print("IMPOSSIBLE");
    }
    
    return 0;
}

Measured memory_bytes: 14192
#include<bits/stdc++.h>
using namespace std;
int n,m;
char mat[2005][2005];
int line[2005][2005];//heng
int row[2005][2005];//shu
int main()
{
    memset(line,0,sizeof(line));
    memset(row,0,sizeof(row));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",mat[i]+1);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(mat[i][j]=='.') line[i][j]=line[i][j-1]+1;
        }
        for(int j=m-1;j>=1;j--)
        {
            if(line[i][j]&&line[i][j+1]) line[i][j]=line[i][j+1];
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(mat[j][i]=='.') row[j][i]=row[j-1][i]+1;
        }
        for(int j=n-1;j>=1;j--)
        {
            if(row[j][i]&&row[j+1][i]) row[j][i]=row[j+1][i];
        }
    }
    int MAX=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            MAX=max(MAX,row[i][j]+line[i][j]);
        }
    }
    printf("%d\n",MAX-1);
}


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


int main(void){
  int k,n; cin >> k >> n;
  int a[n];
  rep(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  int spc = 0;
  for(int i = 1; i< n; i++){
    if(a[i] - a[i-1] > spc) spc = a[i] - a[i-1];
  }
  spc = max(spc,a[0] + k -a[n-1]);
  cout << k - spc << endl;
  return 0;
}


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

int main() {
    string T;
    cin >> T;
    for(int i = 0; i < T.size(); i++) {
        if(T[i] == '?') {
            T[i] = 'D';
        }
    }
    cout << T << endl;
}


Measured memory_bytes: 3720
#include<iostream>
using namespace std;
int main(){
  long long int N,K;
  cin>>N>>K;
  long long int sum=0;
  N++;
  for(long long int i=K; i<=N; i++){
    sum+=(N-i+1)+((N-i)*(i-1));
    sum%=1000000000+7;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n, a;
	cin >> n;
	ll res = 100;
	REP(i, n) {
		cin >> a;
		ll cnt = 0;
		while (a % 2 == 0) {
			a /= 2;
			++cnt;
		}
		res = min(res, cnt);
	}
	cout << res << endl;
	return 0;
}
 

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

int main() {
    int n, m, c = 0, sum = 0;
    bool flag = false;
    cin >> n >> m;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    for(int i = 0; i < n; ++i) {
        if((double)a[i] >= sum/(4.0*m)) c++;
        if(c >= m) {
            flag = true;
            break;
        }  
    }
    if(flag) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}

int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};
int vis[101][101];
int tm;

int main() 
{ 
    fast_io
    go();
    char c;cin>>c;
    if(c>='A' && c<='Z')
      cout << 'A' <<endl;
    else
      cout << 'a' <<endl;
} 

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  //long long ans=0;
  string t;
  cin>>t;
  for(int i=0;i<t.size();i++){ 
    if(t[i]=='?'){
      t.replace(i,1,"D");
    }
  }
  cout<<t<<endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
void solve()
{
    ll n, m;
    cin>>n>>m;
    map<ll, ll> mp1;
    vector<bool> check(n);
    forr(i, m)
    {
        ll place, dig;
        cin>>place>>dig;
        if(mp1.find(place)==mp1.end())
        {
            mp1[place]=dig;
            check[place-1]=true;
        }
        else
        {
            if(mp1[place]!=dig)
            {
                cout<<"-1";
                return;
            }
        }
        if(n!=1&&place==1&&dig==0)
        {
            cout<<"-1";
            return;
        }
    }
    if(n==1)
    {
        cout<<mp1[1];
        return;
    }
    forr1(i, n)
    {
        
        if(check[i-1]||i-1)
        cout<<mp1[i];
        else
        cout<<1;
    }
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   string s,t;
   cin>>s>>t;
   int ans =0;

   for(int i=0;i<3;i++)
   {
       if(s[i] == t[i])
       {
           ans++;
       }
}

cout<<ans;


    

}



Measured memory_bytes: 256
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        n: usize,
        x: u64,
        a_v: [u64; n],
    }

    let mut a_v = a_v;

    let mut answer = 0;
    for i in 0..(n-1) {
        if a_v[i] + a_v[i+1] > x {
            // a_v[i] か a_v[i+1] を食べなければいけない
            let count = a_v[i] + a_v[i+1] - x;    // 食べる回数
            answer += count;

            // できる限り a_v[i+1] をたべたほうが良い
            if count >= a_v[i+1] {
                a_v[i+1] = 0;
            } else {
                a_v[i+1] -= count;
            }
        }
    }

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


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e3+23;
const int S = 1e5+23;
const int mod = 1e9+7;

int n, m;
int a[N], b[N];
long long dp[N][N], sum[N][N];

void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", a+i);
  for (int j = 1; j <= m; ++j) scanf("%d", b+j);
  sum[0][0] = dp[0][0] = 1;
  for (int i = 0; i <= n; ++i) sum[i][0] = 1;
  for (int i = 0; i <= m; ++i) sum[0][i] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) dp[i][j] = (sum[i-1][j-1] + 1) % mod;
      sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j] + mod) % mod;
    }
  }
  printf("%lld", (sum[n][m]+1)*500000004%mod);
}

int main() {
  //  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 66604
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>


#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
	int a, b;
	cin >> a >> b;
	int c = a * b;
	if (c % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;
}


// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;

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

  int ans = 0;
  for(int i = 0; i < N-1; i++){
    int tmp = i+1;
    if(tmp == v[i]){
      ans++;
      v[i] = v[i+1];
      v[i+1] = tmp;
    }
  }

  if(v[N-1] == N){
    ans++;
  }
  cout << ans << endl;



}


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

#define Re return
#define In inline
#define Op operator
#define St static
#define Rg register
#define Ct continue
#define inc(l, i, r) for(Rg int i=l; i<r; ++i)
#define dec(l, i, r) for(Rg int i=r; i>l; --i)
#define fev for(Rg int o=u[h], v; (v=o[e].v)>0; o=o[e].o)
#define mP make_pair
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pInt;
typedef double db;

const int mxN=1<<18;

struct Nod
{
    int s0, s1, id;
    In Nod(int s0=0, int s1=0, int id=0) :
    s0(s0), s1(s1), id(id) {}
    In bool Op <(const Nod& b) const {Re (ll)s0*b.s1<(ll)s1*b.s0;}
} a[mxN];

int bel[mxN];

int get(int x) {Re bel[x]? bel[x]=get(bel[x]): x;}

int main()
{
    St int n;
    scanf("%d", &n);
    St int f[mxN];
    inc(2, i, n+1)
        scanf("%d", f+i);
    inc(1, i, n+1)
    {
        St int k;
        scanf("%d", &k);
        a[i]=Nod(!k, k, i);
    }
    St priority_queue<Nod> q;
    inc(2, i, n+1)
        q.push(a[i]);
    St ll ans[mxN];
    for(;!q.empty();)
    {
        Nod u=q.top();
        q.pop();
        if(a[u.id].s0!=u.s0 || a[u.id].s1!=u.s1) Ct;
        Rg int v=get(f[u.id]);
        bel[u.id]=v;
        ans[v]+=ans[u.id]+(ll)a[v].s1*u.s0;
        a[v]=Nod(a[v].s0+u.s0, a[v].s1+u.s1, v);
        if(v>1) q.push(a[v]);
    }
    printf("%lld\n", ans[1]);
    Re 0;
}


Measured memory_bytes: 10868
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

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

void solve()
{
  int n;
  cin >> n;
  int a=1,b=1,c=1;
  fp(i,1,n)
  {
    a=(a%mod * 10%mod)%mod;
    b=(b%mod * 9%mod)%mod;
    c=(c%mod * 8%mod)%mod;
  }
  b=(2%mod * b%mod)%mod;
  int ans=(a-b+c+mod)%mod;
  cout << ans << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const bool debug =0;

inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
    if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}


const int MAXN = 3e5+100;

vector<int> son[ MAXN ];
int n;
int MAX[ MAXN ],MAXX[ MAXN ];
int ans=0;

void dfs(int x,int fa){
MAX[x]=0;
MAXX[x]=0;
for(auto &y:son[x])
{
    if ( y==fa )    continue;
    dfs(y,x);
    MAXX[x] = max ( MAXX[x] , MAX[y]+1);
    if ( MAXX[x] > MAX[x] )
        swap( MAXX[x] ,  MAX[x] );
}
ans=max(ans,MAXX[x]+MAX[x]+1);
}

int main(){
    read(n);
    for (int i=1;i<n;i++)
    {
        int x,y;
        read(x);read(y);
        son[x].push_back(y);
        son[y].push_back(x);
    }
    dfs(1,0);
    if ( ans%3==2 )
        puts("Second");
    else
        puts("First");

    return 0;
}


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

int main() {
    int N, X; cin >> N >> X;
    int L[N]; for (int i = 0; i < N; ++i) cin >> L[i];

    int res = 1;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += L[i];
        if (X >= sum) res++;
    }

    cout << res << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b; cin >> a >> b;
  if (a <= b) cout << a << endl;
  else cout << a - 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

vector<vector<long long> > g;
vector<long long> t;
long long ans = 1e9, r;

void get_ans(){
    do{
        long long now = 0;
        for(int i = 1; i < r; ++i) now += g[t[i - 1]][t[i]];
        ans = min(ans, now); 
    } while(next_permutation(t.begin(), t.end()));
}

int main(){
    long long n, m;
    cin >> n >> m >> r;
    t.resize(r);
    for(int i = 0; i < r; ++i){
        cin >> t[i];
        t[i]--;
    }
    g.assign(n, vector<long long>(n, 1e9));
    long long fr, to, c;
    for(int i = 0; i < m; ++i){
        cin >> fr >> to >> c;
        fr--, to--;
        g[fr][to] = c;
        g[to][fr] = c;
    }
    for(int i = 0; i < n; ++i)
       for(int j = 0; j < n; ++j)
           for(int x = 0; x < n; ++x)
               g[j][x] = min(g[j][x], g[j][i] + g[i][x]);
    sort(t.begin(), t.end());
    get_ans();
    cout << ans;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x)  cout << #x << " = " << (x) << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int main() {
    ll n, k, ans;
    ll c[5005], p[5005];

    cin >> n >> k;
    for (ll i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (ll i = 1; i <= n; i++) {
        cin >> c[i];
    }

    ans = c[1];
    for (ll i = 1; i <= n; i++) {
        ll cur = i, now = 0, sum = 0, round = 0;
        bool flag = false;
        for (ll j = 1; j <= k; j++) {
            cur = p[cur];
            now += c[cur];
            if(cur == i){
                if(flag) break;
                flag = true, sum = now, round = j;
            }
            ans = max(now, ans);
            if(flag) ans = max(ans, now + (k - j) / round * sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3700
import collections
import sys
N = int(input())
S = [input() for _ in range(N)]

c = collections.Counter(S)
ans = []
li=c.most_common()
for i in range(len(li)):
    if i == 0:
        ans.append(((li[0][0])))
    
    if i != 0:
        if (li[i-1][1]) == (li[i][1]):
            
            ans.append(((li[i][0])))
        else:
            break

ans.sort()

for i in ans:
    print(i)

Measured memory_bytes: 47636
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int t=0, N, buf;
    int sum=0;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> buf;
        sum+=buf;
        if(buf%10 != 0){
            if(buf < t || t==0){
                t= buf;
            }
        }
    }
    if(sum%10 == 0){
        if(t==0){
            cout << 0 << endl;
        }else{
            cout << sum - t << endl;
        }
    }else{
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    int n;
    int ans = 0;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    
    
    int ba = 0, _a = 0, b_ = 0;
    
    for(auto e:s){
        for(int i = 0; i < e.size()-1;i++){
            if (e[i] == 'A' && e[i+1] == 'B') ans++;
        }
        
        if (e[0] == 'B' && e.back() == 'A') ba++;
        else if (e[0] =='B') b_++;
        else if (e.back() == 'A') _a++;
    }
    

    if (ba) ans += ba-1;
    
    if (_a && ba){
        ans++;
        _a--;
    }
    
    if (b_ && ba){
        ans++;
        b_--;
    }
    
    ans += min(b_,_a);
    
    cout << ans;
    
    
}



int main(){
    int T;
    T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}





































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

typedef long long ll;
typedef pair<int,int> pii;

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

const int MAX = 1e5+9;
const ll MOD = 1e9+7;

ll a[MAX];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n, L;
	cin >> n >> L;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n-1; i++)
		if (a[i] + a[i+1] >= L) {
			cout << "Possible\n";
			for (int t = 1; t <= i; t++)
				cout << t << "\n";
			for (int t = n-1; t >= i+2; t--)
				cout << t << "\n";
			cout << i+1 << "\n";
			return 0;
		}
	cout << "Impossible\n";
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll A, B, C;
	unsigned ll K;
	cin >> A >> B >> C >> K;
	if (K % 2 == 0) {
		cout << A - B;
	}
	else {
		cout << B - A;
	}

	return 0;


}

Measured memory_bytes: 256
N, M, P = map(int, input().split())
edges = []
for i in range(M):
    A, B, C = map(int, input().split())
    edges.append([A, B, P - C])


def BellmanFord(edges, num_v, source):
    minus_flag = 0
    inf_flag = 0
    # グラフの初期化
    inf = float("inf")
    dist = [inf for i in range(num_v)]
    dist[source - 1] = 0

    # 辺の緩和
    for i in range(num_v * 3):
        for edge in edges:
            if edge[0] != inf and dist[edge[1] - 1] > dist[edge[0] - 1] + edge[2]:
                dist[edge[1] - 1] = dist[edge[0] - 1] + edge[2]
                if i == num_v - 1:
                    minus_flag = 1
                if minus_flag == 1:
                    if edge[1] == N:
                        inf_flag = 1

    if inf_flag == 0:
        return dist
    else:
        dist.append(-1)
        return dist


ans = BellmanFord(edges, N, 1)
if len(ans) != N:
    print(-1)
else:
    print(max(0, ans[-1] * -1))


Measured memory_bytes: 48492
//https://atcoder.jp/contests/apc001/tasks/apc001_b
//B - Two Arrays
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-2.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<ll> an(N),bn(N);
    for(auto&& a:an){
        cin>>a;
    }
    for(auto&& b:bn){
        cin>>b;
    }
    // sort(an.begin(),an.end());
    // sort(bn.begin(),bn.end());
    ll a_rest=0;
    REP(i,N){
        auto a=an.at(i);
        auto b=bn.at(i);
        a_rest += max((a-b)*2,0LL);
    }
    REP(i,N){
        auto a=an.at(i);
        auto b=bn.at(i);
        auto tmp=max(b-a,0LL)/2;
        a_rest -= tmp*2;
    }
    cout<<(a_rest<=0?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(int argc, char* argv[]) {
    int N;
    std::cin >> N;
    int T, A;
    std::cin >> T >> A;
    auto H = new int[N];

    for (int i = 0; i < N; i++) {
        std::cin >> H[i];
    }

    int diff_min = INT_MAX;
    int diff_i = 0;
    for (int i = 0; i < N; i++) {
        auto v = T * 1000 - (H[i] * 6);

        int diff = v - A * 1000;
        auto abs_diff = std::abs(diff);
        if (abs_diff < diff_min) {
            diff_i = i;
            diff_min = abs_diff;
        }
    }

    std::cout << diff_i + 1 << std::endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

const int M=998244353;

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

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

    int l[k],r[k];
    for(int i=0;i<k;i++)
    	cin>>l[i]>>r[i];

    int dp[n+1]={0};
    int pref[n+1]={0};

    dp[1]=1;
    pref[1]=1;

    for(int i=2;i<=n;i++)
    {
    	for(int j=0;j<k;j++)
    	{
    		if(l[j]>=i)
    			continue;
    		int l1=l[j],r1=min(i-1,r[j]);
    		int temp=(pref[i-l1]-pref[i-r1-1]+M)%M;
    		dp[i]=(dp[i]+temp)%M;
    	}

    	pref[i]=(pref[i-1]+dp[i])%M;
    }

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

Measured memory_bytes: 5156
n, a, b, c, d = map(int, input().split())
s = str(input())

flag = True

# c < dならbを先にゴールさせれば良い
s_bd = s[b:d-1]
for i in range(len(s_bd)-1):
    if s_bd[i:i+2] == "##":
        flag = False
        break
s_ac = s[a:c-1]
for i in range(len(s_ac)-1):
    if s_ac[i:i+2] == "##":
        flag = False
        break

if c > d:
    # ゴールの左が#
    if s[d-2] == "#":
        s_bd = s[b-2:d]
        has_ddd = False
        for i in range(len(s_bd)-2):
            if s_bd[i:i+3] == "...":
                has_ddd = True
        if has_ddd == False:
            flag = False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    string s; cin >> s;
    int ct = 0;
    rep(i,s.size()) if (s[i] == 'p') ct++;
    cout << -ct + s.size()/2 << endl;
}

Measured memory_bytes: 512
import bisect

A, B, Q = [int(i) for i in input().split()]

s = [-10**12] + [int(input()) for i in range(A)] + [10**12]
t = [-10**12] + [int(input()) for i in range(B)] + [10**12]
x = [int(input()) for i in range(Q)]

for item in x:
    a, c = bisect.bisect_left(s, item), bisect.bisect_left(t, item)
    min_value = 10**12
    for item_a in [s[a-1], s[a]]:
        for item_c in [t[c-1], t[c]]:
            pata = abs(item_a - item) + abs(item_a - item_c)
            patb = abs(item_c - item) + abs(item_a - item_c)
            min_value = min(min_value, pata, patb)
    print(min_value)


Measured memory_bytes: 16188
# Queue - Round-robin Scheduling
class Proc:
    def __init__(self, strs):
        self.name = strs[0]
        self.time = int(strs[1])
n,q = map(int, input().split(' '))
que = [Proc(input().split(' ')) for _ in range(n)]
proc_time = 0
while len(que) > 0:
    p = que.pop(0)
    if p.time <= q:
        proc_time += p.time
        print(p.name, proc_time)
    else:
        proc_time += q
        p.time -= q
        que.append(p)


Measured memory_bytes: 19236
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> p1,pair<int,int> p2)
{
    return p1.first>p2.first;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    vector<pair<int,int>> v;
    pair<int,int> p;
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        p=make_pair(y,x);
        v.push_back(p);
    }
    sort(v.begin(),v.end(),comp);
    /*for(int i=0;i<n;i++)
        cout<<a[i]<<" ";*/
    //cout<<endl;
    int i=0;
    for(auto it=v.begin();it!=v.end();it++)
    {
        int no=it->second;
        while(no--)
        {
            if(a[i]<it->first && i<n)
                a[i++]=it->first;
            else
                break;
        }
    }
    long long sum=0;
    for(int c=0;c<n;c++)
        sum+=a[c];
    cout<<sum<<endl;
}

Measured memory_bytes: 1784
n, k, q = map(int, input().split())
a = list(map(int, [input() for i in range(q)]))
p = [k-q] * n
for i in range(q):
  p[a[i]-1] += 1
for i in range(n):
  print('Yes' if p[i] > 0 else 'No')

Measured memory_bytes: 13356
n = int(input())
A = list(map(int, input().split()))

#左から丹頂非増加、単調非減少を試して行って長い方を採用すれば良いO(N)
#値の増減の反転するポイントを探索する

ans = 1
tmp = 0
for i in range(1, n):
    if (A[i] - A[i-1]) * tmp < 0:
        ans += 1
        tmp = 0
    elif A[i] - A[i-1] != 0:
        tmp = A[i] - A[i-1]

print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N, K; cin >> N >> K;
    int mx = (N-1)*(N-2)/2;

    if(K>mx){
        cout << -1 << endl;
        return 0;
    }
    
    vector<vector<bool>> E(N, vector<bool>(N));
    
    cout << mx - K + N - 1 << endl;
    
    for(int i=0; i<N-1; i++){
        cout << i+1 << " " << N << endl;
        E[i][N-1] = true;
        E[N-1][i] = true;
    }
    
    int cnt = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i==j) continue;
            if(cnt >= mx-K) break;
            if(!E[i][j]){
                E[i][j] = true;
                E[j][i] = true;
                cnt++;
                cout << i+1 << " " << j+1 << endl;
            }
        }
    }

    
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<math.h>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,x1,x2,x3;
	scanf("%d%d",&a,&b);
	x1=a+b;
	x2=a-b;
	x3=a*b;
	if(x2>x1)
		x1=x2;
	if(x3>x1)
		x1=x3;
	printf("%d",x1);
	return 0;
}

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

cnt = 0
breakflg = 0
while breakflg == 0:
    for i in range(N-1):
        if A[i] %2 == 1:
            breakflg = 1
    
    if breakflg == 1:
        break
    
    for i in range(N-1):
        A[i] /= 2    
    cnt += 1

print(cnt)

Measured memory_bytes: 3060