akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

static const int MAX = 100005;
int N, M, p[MAX];
bool vis[MAX];
vector<int> g[MAX];
vector<int> id;
vector<int> pi;

void dfs(int idx) {
  int next;
  id.push_back(idx);
  pi.push_back(p[idx]);
  vis[idx] = true;
  rep(i, g[idx].size()) {
    next = g[idx][i];
    if (!vis[next]) dfs(next);
  }
}

int main() {
  cin >> N >> M;
  rep(i, N) {
    int a;
    cin >> a;
    p[a] = i + 1;
  }

  rep(i, N) vis[i + 1] = false;

  rep(i, M) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }


  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (!vis[i]) {
      id.erase(id.begin(), id.end());
      pi.erase(pi.begin(), pi.end());
      dfs(i);
      sort(id.begin(), id.end());
      for (int elem : pi) {
        if (binary_search(id.begin(), id.end(), elem)) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 10156
import collections
n = int(input())
An = list(map(int, input().split()))
lst = collections.Counter(An)
c_lst = {k: int(v*(v-1)/2) if v > 1 else 0 for k, v in lst.items()}
count = sum(c_lst.values())
for k in An:
  print(count - max(lst[k]-1, 0))

Measured memory_bytes: 30780
char*p,*h,*r,s[1025],t[52];main(){for(;~scanf("%*d%s"+!!h*3,s);puts(h))for(h=p=memset(t,0,52)+25,r=s-1;*p=*++r,*++r;)*++r-62?--p<h?h=p:0:++p;}

Measured memory_bytes: 0
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, K = LI()

def fact(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(1, n+1):
        ret *= i
    return ret


for i in range(1, K+1):
    if (N-K-i+1>= 0):
        t1 = math.factorial(N-K+1)
        t2 = math.factorial(i)
        t3 = math.factorial(N-K-i+1)
        tmp1 = (t1//(t2*t3))%mod

        t4 = math.factorial(K-1)
        t5 = math.factorial(i-1)
        t6 = math.factorial(K-i)
        tmp2 = (t4//(t5*t6))%mod

        print(tmp1 * tmp2 % mod)
    else:
        print(0)

Measured memory_bytes: 65624
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vvl m = vv(n, n, 0, ll);
  vvl e = vv(0, 3, 0, ll);
  ll ans = 0;
  re(i, n) {
    re(j, n) {
      std::cin >> m[i][j];
      e.push_back(vll{m[i][j], i, j});
      ans += m[i][j];
    }
  }
  sort(e.begin(), e.end());
  reverse(e.begin(), e.end());
  //std::cout << ans << '\n';
  re(i, e.size()){
    ll s = e[i][1], t = e[i][2], c = e[i][0];
    //std::cout << "now" << i<< '\n';
    //std::cout << s << " " << t << " " << c << '\n';
    re(j, n){
      if(j==s||j==t) continue;
      if(m[s][j]+m[j][t]<c){
        std::cout << -1 << '\n';
        return 0;
      }
      if(m[s][j]+m[j][t]==c) {
        ans-=c;
        break;
      }
    }
  }
  std::cout << ans/2 << '\n';
  return 0;
}


Measured memory_bytes: 7476
N = int(input())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = int(input())
    
dp = [[False for i in range(10001)] for j in range(N)]

dp[0][s[0]] = True
dp[0][0] = True
for i in range(1, N):
    for j in range(10001):
        dp[i][j] |= dp[i - 1][j]
        if dp[i - 1][j]  and j + s[i] <= 10000:
            dp[i][j + s[i]] = True
            
for i in range(10000, -1, -1):
    if dp[N - 1][i] and (i % 10 != 0 or i == 0):
        print(i)
        break

Measured memory_bytes: 11336
# import sys
# import numpy as np

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    solve()


def solve():
    N, X, Y = map(int, input().split())

    ans_list = [0 for _ in range(N)]
    for i in range(N-1):
        for j in range(i+1, N):
            dist1 = j-i
            dist2 = abs(X-i-1) + 1 + abs(Y-j-1)

            ans = min(dist1, dist2)
            ans_list[ans] += 1

    for n in ans_list[1:]:
        print(n)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;

ll power(ll a , ll n)
{
    unsigned long long int result=1,x=a;
    while(n>0)
    {
        if(n % 2 ==1)
            result = (result * x)%MOD;
        x = (x * x)%MOD;
        n=n/2;
    }
    return result;
}

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


int main() 
{ 
    FIO
    int t;
    t=1;
    while(t--)
    {   
        int x,y;
        cin >> x >> y;
        
        int p1 = y - 2*x;
        int p2 = 4*x - y;
        
        if(p1%2 || p2%2)
        {
            cout << "No" << endl;
            return 0;
        }
        
        if(p1>=0 && p2>=0)
        {
            cout << "Yes" << endl;
        }
        else
            cout << "No" << endl;
    }
    return 0; 
}


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

count=0
for i in range(N):
  if A[i]%2==0 and (A[i]%3!=0 and A[i]%5!=0):
    print("DENIED")
    count=1
    break

if count==0:
  print("APPROVED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
//#define PI 3.14159265358979323846264338327950L
using namespace std;

void solve()
{
    int arr[6];
    for(int i=1;i<=5;++i)
    {
        cin >> arr[i];
        if(arr[i]==0)
        {
            cout << i << endl;
            break;
        }
    }
    

    
}


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    /*int t;
    cin >> t;
   while(t--)
    {
         solve();  
    }
   */solve();
    return 0;
}



Measured memory_bytes: 3580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	stdin.Scan()
	text := stdin.Text()
	a, _ := strconv.Atoi(strings.Split(text, " ")[0])
	b, _ := strconv.Atoi(strings.Split(text, " ")[1])

	if a%2 == 0 || b%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}


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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    set<ll> s;
    rep(i,3){
        ll x; cin>>x; s.insert(x);
    }
    if(s.size() == 2) puts("Yes");
    else puts("No");

    return 0;

}

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

SUM=[0]
for a in A:
    SUM.append((SUM[-1]+a)%M)

from collections import Counter
counter=Counter(SUM)

ANS=0
for i in counter.values():
    ANS+=i*(i-1)//2

print(ANS)

Measured memory_bytes: 16556
#include <stdio.h>

int mod(int a, int b) {
	if (a == 0) {
		return b;
	}
	else {
		return mod(b%a, a);
	}
}

int main()
{
	int n;
	int a[200000];

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

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] == cnt + 1) {
			cnt++;
		}
	}

	if (cnt > 0) {
		printf("%d", n - cnt);
	}
	else {
		printf("%d", -1);
	}
}

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

int main(void){

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << sqrt(pow(fabs(x1-x2),2)+pow(fabs(y1-y2),2)) << endl;
    return 0;
}



Measured memory_bytes: 3256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

bool find(int k) {
  Node *x = root;
  while (x != NIL) {
    if (k == x->key) {
      return true;
    } else if (k < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  return false;
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "find") {
      scanf("%d", &x);
      if (find(x)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 22052
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a+b >= k) cout << min(a,k) << endl;
  else cout << a-(k-a-b) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
  int n,c,i;
  char s[11000];
  scanf("%d%s",&n,s);
  for(i=0;s[i]!='\0';i++){
    c = s[i]-'A'+n;
    printf("%c",c%26+'A');
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

int a,b,sum,i;

int main(){

	scanf("%d%d",&a,&b);
	for(i=1;i<999;i++){
		sum+=i;
		if(sum-a==sum+i+1-b)
			break;
	}
	printf("%d\n",sum-a);
	//system("pause");

	return 0;
}


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

int main()
{
	int n;
	ignore = scanf("%d", &n);
	int s = 0;
	for (int i = 0; i < n; i++) {
		int x;
		ignore = scanf("%d", &x);
		s ^= x;
	}
	
	if (s == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[]) {
	
	int a1,b1,sum1,tenpower1,i1,digit1;
	
	while(scanf("%d %d", &a1, &b1)!=EOF) {
		
	sum1=a1+b1;i1=0;digit1=-1;

	
	do{
		
		tenpower1=pow(10,i1);
		digit1=digit1+1;
		i1++;
		
	}while(sum1/tenpower1>=1);
	
	printf("%d\n",digit1);
	

    
}
	

	
return(0);	

}


Measured memory_bytes: 1932
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
 
int par[100000];
void init(int n){
	rep(i,n){
		par[i]=i;
	}
}
 
int root(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x] = root(par[x]);
	}
}
 
void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y)return;
	par[x]=y;
}
 
 
 
struct a{
	ll a;
	int num;
	int par;
	bool use;
};
 
bool operator< (const a& left,const a& right){
        return left.a < right.a;
}

/*
rep(i,n){
	cin>>aa[i].a;
	aa[i].num=i;
}*/
 
 
 
int main(void){

	ll k,a,b;
	cin>>k>>a>>b;
	ll value = b-a;
	if(value <=2){
		cout<<1+k<<endl;
		return 0;
	}
	ll remain = k-(a-1);
	if(remain <= 0){
		cout<<1+k<<endl;
		return 0;
	}
	if(remain%2 == 0){
		cout<<a+remain/2*value<<endl;
	}else{
		cout<<a+1+(remain-1)/2*value<<endl;
	}



	
	
 
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
  if a[i] == i+1:
    a[i],a[i+1] = a[i+1],a[i]
    cnt += 1
if a[-1] == n:
  cnt += 1
print(cnt)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> sum(n+1);
  rep(i,n) sum[i+1] = sum[i] + a[i];
  ll mx = sum[n];
  ll ans = mx;
  rep(i,n-1) {
    ll l = sum[i+1];
    ll r = mx - l;
    ans = min(ans, abs(l - r));
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 6424
N = gets.to_i
S = gets.strip.split(//)

counts = {}

S.each{|c|
	if counts[c]
		counts[c] += 1
	else
		counts[c] = 1
	end
}

total = 1
counts.each{|c, count|
	total *= (count + 1)
}

puts (total - 1) % (10 ** 9 + 7)



Measured memory_bytes: 6908
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    int N;
    int p[MAXN];
    void solve(){
        ios::sync_with_stdio(false);
        cin>>N;
        for(int u=1;u<=N;u++)cin>>p[u];
        int ans=0;
        for(int u=1;u<=N;u++){
            if(u==N){
                if(p[u]==u){
                    swap(p[u],p[u-1]);
                    ans++;
                }
            }
            else {
                if(p[u]==u){
                    swap(p[u],p[u+1]);
                    ans++;
                }
            }
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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

int main() {
	int N;
	cin >> N;
	vector<int> item(N);
	int sum = 0;
	for (int i  = 0; i < N; i++) {
		cin >> item[i];
		sum += item[i];
	}
	sort(item.begin(), item.end());
	sum -= item[N-1]/2;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int sum=0,s1=0,s2=0;
    cin>>n;
    int arr[n];
    int ano[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum=sum+arr[i];
    }
    for(int i=0;i<n;i++)
    {
        s1=s1+arr[i];
        s2=sum-s1;
        ano[i]=abs(s1-s2);
    }
    sort(ano,ano+n);
    cout<<ano[0]<<endl;

}


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

#define ABS(N) ((N<0)?(-N):(N))

// int gcd( int m, int n )
// {
//   // 引数に０がある場合は０を返す
//   if ( ( 0 == m ) || ( 0 == n ) )
//     return 0;

//   // ユークリッドの方法
//   while( m != n )
//   {
//     if ( m > n ) m = m - n;
//     else         n = n - m;
//   }
//   return m;
// }//gcd

// int lcm( int m, int n )
// {
//   // 引数に０がある場合は０を返す
//   if ( ( 0 == m ) || ( 0 == n ) )
//     return 0;

//   return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
// }//lcm


int main(int argc, char const *argv[])
{
  int N,buf,sum=0;
  vector<int> a;
  cin >> N;

  for (int i = 0; i < N; ++i)
  {
    cin >> buf;
    sum += buf -1;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


#define max 7368792

int main()
{
	while (1) {
		int m, n;
		cin >> m >> n;

		if (m == 0 && n == 0) {
			return 0;
		} else {
			if (m >= n) {
				cout << m + n << endl;
			} else {
				vector<bool> v(max);
				int j = m;
				REP(i, n)
				{
					while (v[j]) j++;
					for (int k = j; k < v.size(); k += j) {
						v[k] = true;
					}
				}

				while (v[j]) j++;
				cout << j << endl;
			}
		}
	}
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

int main(){
    int n, m;
    cin >> n >> m;
    vi c(m);
    for(auto &x : c) cin >> x;
    vi dp(n+1, INF);
    dp[0]=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<m; j++){
            if(c[j] <= i)  dp[i]=min(dp[i], dp[i-c[j]]+1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3168
from sys import stdin

while True:
    H, W = [int(x) for x in stdin.readline().rstrip().split()]
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if (i+j)%2 == 0:
                    print("#", end="")
                else:
                    print(".", end="")
            else:
                print()
        else:
            print()


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N;
    cin >> N;
    map<LL, LL> a;
    a.clear();
    REP(i, N) {
        LL x;
        cin >> x;
        a[x] += 1;
    }

    LL s = 0;
    for(auto i = a.begin(); i != a.end();i++) {
        LL x = i->first;
        LL y = i->second;
        if(x <= y) {
            s += y - x;
        }else{
            s += y;
        }
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 6272
#include<stdio.h>

int main(){
  int w, h, x, y, r;
  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
  if(w < x+r || 0 > x-r || h < y+r || 0 > y-r)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<double> V(N);
  for (int i = 0; i < N; ++i) {
    cin >> V[i];
  }
  sort(V.begin(), V.end());
  double result = (V[0] + V[1]) / 2;
  for (int i = 2; i < N; ++i) {
    double cur_vi = V[i];
    result = (result + cur_vi) / 2;
  }
  cout << result << endl;
}

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

using namespace std;


int main(int argc, char* argv[]){
    int N, K, C;
    string s;
    cin >> K;

    queue<long long> lun_queue;

    for(int i = 0; i < 9; ++i){
        lun_queue.push(i+1);
    }

    long long num;

    for(int i = 0; i < K; ++i){
        num = lun_queue.front();
        lun_queue.pop();

        long long bottom = num % 10;
        if(bottom != 0){
            lun_queue.push(num * 10 + bottom - 1);
        }
        lun_queue.push(num * 10 + bottom);
        if(bottom != 9){
            lun_queue.push(num * 10 + bottom + 1);
        }
    }

    cout << num;
}


Measured memory_bytes: 1792
#include<stdio.h>

long a;
long b[100000];
int i;
long min = 1000000;
long max = -1000000;
long sum;

int main(void){
	
	scanf("%ld",&a);
	for(i=0;i<a;i++){
		scanf("%ld",&b[i]);
	}
	for(i=0;i<a;i++){
		if(b[i] < min){
			min = b[i];
		}
			if(b[i] > max){
				max = b[i];
			}
		
	sum = sum + b[i];
	}
	printf("%ld %ld %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 684
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    ans = [-1]* n
    for s, c in sc:
        s -= 1 
        if ans[s] == -1or ans[s] == c:
            ans[s] = c
        else:
            print(-1)
            return
        
    if ans[0] == -1 and n >1:
        ans[0] = 1
    elif ans[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return
    
    print(''.join(list(map(str, ans))).replace('-1', '0'))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	int x;
	cin>>x;

	if(400<=x&&x<=599)cout<<"8"<<endl;
	else if(600<=x&&x<=799)cout<<"7"<<endl;
	else if(800<=x&&x<=999)cout<<"6"<<endl;
	else if(1000<=x&&x<=1199)cout<<"5"<<endl;
	else if(1200<=x&&x<=1399)cout<<"4"<<endl;
	else if(1400<=x&&x<=1599)cout<<"3"<<endl;
	else if(1600<=x&&x<=1799)cout<<"2"<<endl;
	else if(1800<=x&&x<=1999)cout<<"1"<<endl;

	return 0;
}


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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 100000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

class UnionFind{
public:
    vector<long long int> par; //par[i] : iの親の番号
    vector<long long int> rnk; //root[i] : iの木のランク

    //コンストラクタ
    UnionFind(long long int n): par(n), rnk(n){
        //木の初期化
        for(long long int i = 0; i < n; i++){
            par[i] = i;
            rnk[i] = 1;
        }
    }

    //データxが属する木の根を再帰で取得
    long long int root(long long int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = root(par[x]);
        }
    }

    //xとyが同じ木に属しているかを判定
    bool same(long long int x, long long int y){
        return root(x) == root(y);
    }

    //xとyの木を併合
    void unite(long long int x, long long int y){
        long long int rx = root(x); //xの根
        long long int ry = root(y); //yの根
        if(rx == ry) return; //根が同じならそのまま

        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
        }else{
            par[ry] =rx;
            if(rnk[rx] == rnk[ry]) rnk[rx]++;
        }
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> p(n);

    int i;
    for(i = 0; i < n; i++){
        cin >> p[i];
    }

    UnionFind uf(n);

    int x, y;
    for(i = 0; i < m; i++){
        cin >> x >> y;
        uf.unite(x-1, y-1);
    }

    int count = 0;
    for(i = 0; i < n; i++){
        if(uf.same(i, p[i]-1)){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 2176
n = int(input())
H = list(map(int, input().split()))
H.append(0)
cost = [-1] * (n+1)

cost[0] = 0
cost[1] = abs(H[0]-H[1])

for i in range(n-1):
    step_one = cost[i] + abs(H[i]-H[i+1])
    step_two = cost[i] + abs(H[i]-H[i+2])
    if step_one < cost[i+1]:
        cost[i+1] = step_one

    cost[i+2] = step_two

print(cost[n-1])

Measured memory_bytes: 13980
def gcd(a,b)
    a,b = b,a%b while b > 0
    a
end

N,X = STDIN.gets.split.map(&:to_i)
x = STDIN.gets.split.map(&:to_i).map{|i| i - X}
puts x.reduce(x[0]){|a, b| gcd(a.abs, b.abs)}.abs


Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n],i,j,k,ans=0;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if((a[i]+a[j]>a[k]) && (a[i]!=a[j] && a[j]!=a[k]))
                    ans++;
            }
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3636
"""
スタックのデータ構造の定義
"""

class Stack:
    def __init__(self):
        self.stack = []

    def push(self, num):
        self.stack.append(num)

    def individual_push(self, num):
        self.stack.append(num)

    def pop(self):
        if len(self.stack) > 0:
            return True, self.stack.pop(-1)
        else:
            return False, 0
    
    def push_individual(self, left_index, current_index):
        sum_a = 0
        for pair in reversed(self.stack):
            if pair[0] > left_index:
                _, a = self.pop()
                sum_a += a[1]
            else:
                break
        self.push((left_index, sum_a + (current_index - left_index)))

    def print_individual_volume(self):
        volume_list = [str(s[1]) for s in self.stack]
        if len(volume_list) == 0:
            print(0)
        else:
            print("{} ".format(len(volume_list)) + " ".join(volume_list))


if __name__=="__main__":
    input_values = input()

    stack1 = Stack()
    stack2 = Stack()
    area_sum = 0

    for i, v in enumerate(input_values):
        # print(i)

        if v == "\\":
            stack1.push(i)
        elif v == "/":
            result, pop_value = stack1.pop()
            if result:
                area = i - pop_value
                stack2.push_individual(pop_value, i)
            else:
                area = 0
            area_sum += area

    print(area_sum)
    stack2.print_individual_volume()


Measured memory_bytes: 6192
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


 
void solve(){
    ll a,b;
    cin>>a>>b;
    if(a==1&&b==1) cout<<"Draw"<<endl;
    else if(a==1) cout<<"Alice"<<endl;
    else if(b==1) cout<<"Bob"<<endl;
    else {
        if(a>b) cout<<"Alice"<<endl;
        else if(a<b) cout<<"Bob"<<endl;
        else cout<<"Draw"<<endl;
    }

}
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
     int main() {
       std::string A, B, C;
       std::cin >> A >> B >> C;
       if (A.back() == B.front() && B.back() == C.front()) {
         std::cout << "YES" <<std::endl;
       } else {
         std::cout << "NO" <<std::endl;
       }
       
       
       return 0;
       
       
     }

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        xl:[(isize,isize);n],
    }

    let mut robots = xl.into_iter().map(|(x, l)| (x - l, x + l)).collect_vec();

    robots.sort_by_key(|&(_left, right)| right);

    let mut now_right = -I_INF;
    let mut ans = 0;

    for &(l, r) in &robots {
        if l < now_right {
            ans += 1;
            continue;
        }

        now_right = r;
    }

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


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

// mod（素数だけ）の処理を忘れさせてくれるライブラリ
// https://github.com/atcoder-live/library/blob/master/mint.cpp
const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0):x((x % mod + mod) % mod) {}
  mint operator-() const {return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {

  long long N, K;
  cin >> N >> K;

  mint answer = 0;

  for (long long j = K; j <= N + 1; j++) {
    mint mn = j * (j + 1) / 2 - j;
    mint mx = N * j - mn.x;
    mint same = (N + 1) / j - 1;
    answer += mx.x - mn.x + 1;
  }

  cout << answer.x << endl;

  return 0;

}

Measured memory_bytes: 3596
#include <stdio.h>

int main() {
	int n;
	int hi;
	int count = 1;
	scanf("%d", &n);
	scanf("%d", &hi);
	int aux = hi;
	for (int i = 1; i < n; i++){
		scanf("%d", &hi);
		if(aux <= hi){
			count++;
			aux = hi;
		}

	}
	printf("%d\n", count);


	return 0;
}

Measured memory_bytes: 128
N, M = [int(i) for i in input().split()]
a = [0] * N
wa = [0] * N
ac = 0
WA = 0
for i in range(M):
    t, s = input().split()
    t = int(t)-1
    if s == 'AC':
        a[t] = 1
    elif s == 'WA':
        if a[t]==0:
            wa[t] += 1
for i in range(N):
    if a[i]==1:
        ac += 1
        WA += wa[i]
print(ac, WA)


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

using namespace std;

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

	int x = 0;
	int res = 0;
	int n;
	string s;
	cin >> n >> s;
	for (char c : s) {
		if (c == 'I') {
			x++;
		} else {
			x--;
		}
		res = max(res, x);
	}
	cout << res << '\n';

	return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<pair<string,int>>A(N),B(N);
  for(int i=0;i<N;i++)cin>>A[i].first>>A[i].second;
  for(int i=0;i<N;i++)A[i].second*=-1;
  B=A;
  sort(rng(A));
  for(int i=0;i<A.size();i++){
    for(int j=0;j<B.size();j++){
      if(A[i]==B[j]){
        cout<<j+1<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#[test]
fn test_solve() {
   assert_eq!(solve("4\n1\n3\n2\n4\n"), "2\n");
   assert_eq!(solve("6\n3\n2\n5\n1\n4\n6\n"), "4\n");
   assert_eq!(solve("8\n6\n3\n1\n2\n7\n4\n8\n5\n"), "5\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    
    use std::collections::HashMap;
    let mut wait = HashMap::new();

    for _ in 0..n {
        let p: usize = sc.read();
        if let Some(v) = wait.remove(&(p-1)) {
            wait.insert(p, v+1);
        } else {
            wait.insert(p, 1);
        }
    }

    let lgis = wait.iter().map(|pn| pn.1).max().unwrap();

    format!("{}\n", n - lgis)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

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

A.sort(reverse= True)

ans = 0
ind = 0
for i in range(N-1):
    if i == 0:
        ans += A[ind]
        ind += 1
    elif i % 2 == 1:
        ans += A[ind]
    else:
        ans += A[ind]
        ind += 1

print(ans)
    

Measured memory_bytes: 31444
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    string s;
    cin >> s;
    bool flag = false;
    int cnt[26] = { 0 };
    FOR(i, 0, s.size()) {
        cnt[s[i] - 'a']++;
    }
    FOR(i, 0, 26) {
        if (cnt[i] >= 2)
            flag = true;
    }
    cout << (!flag ? "yes" : "no") << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0; i<N; i++) cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans=0;
  for(int i=0; i<N-1; i++){
    v.at(i+1)=(v.at(i)+v.at(i+1))/2;
    ans=v.at(i+1);
  }
  std::cout << std::setprecision(18) << ans << endl;
}

Measured memory_bytes: 256
import itertools

info = [int(input()) for i in range(4)]
A = (i for i in range(info[0]+1))
B = (i for i in range(info[1]+1))
C = (i for i in range(info[2]+1))

P_L = list(itertools.product(A, B, C))
ans = 0

for ele in P_L:
    if 500*ele[0] + 100*ele[1] + 50*ele[2] - info[3] == 0: ans += 1

print(ans)

Measured memory_bytes: 13604
import java.util.*;

public class Main {

    static long mod = 1_000_000_007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] sum = new long[n+1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i-1] + i;
        }
        long ans = 1L;
        for (int i = k; i <= n; i++) {
            long min = sum[i-1]-1;
            long max = sum[n] - sum[n-i];
            ans = (ans + max - min) %mod;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 37216
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};


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



int main() {
    int n; cin >> n;
    vector<int> a(n);
    int mx = 0, mmx = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] > mx) {
            mmx = mx;
            mx = a[i];
        } else if (mx >= a[i] && a[i] > mmx) {
            mmx = a[i];
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (a[i] == mx) cout << mmx << endl;
        else cout << mx << endl;
    }
    

    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>

int main(){
	int n;
	std::vector<unsigned long long> aList;
	std::vector<int> digit;

	std::cin>>n;
	aList.resize(n);
	digit.resize(n, 0);

	for(int i=0; i< n; i++)
		std::cin>>aList[i];

	for(int i=0; i< n; i++){
		unsigned long long tmp= aList[i];

		while(tmp>0){
			tmp/=10;
			digit[i]++;
		}
	}

	unsigned long long prod= aList[0];	
	int pDigit= digit[0];
	bool isOver18= false;


	for(int i=1; i< n; i++){
		if(pDigit + digit[i] - 2 > 18){
			isOver18= true;
			break;
		}
		else if(pDigit + digit[i] - 2 == 18){
			long long pTmp= prod;
			long long tmp= aList[i];

			for(int j=0; j< pDigit-1; j++)				
				pTmp/=10;
			
			for(int j=0; j< digit[i]-1; j++)
				tmp/= 10;

			if(pTmp * tmp > 2){
				isOver18= true;
				break;
			}
		}

		if(prod * aList[i]> 1000000000000000000){
			isOver18=true;
			break;
		}else{
			prod*= aList[i];

			unsigned long long tmp= prod;
			pDigit= 0;

			while(tmp>0){
				tmp/=10;
				pDigit++;
			}	
		}

	}

	bool isExist0= false;
	for(int i=0; i<n; i++){
		if(aList[i]==0)
			isExist0=true;
	}

	if(isExist0){
		std::cout<<0<<std::endl;
	}else{

	if(isOver18)
		std::cout<<-1<<std::endl;
	else
		std::cout<<prod<<std::endl;
}

}

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

namespace abc163_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var summerVacationDaysAndHomeWorkNum = Console.ReadLine().Split(' ');
            var homeWorkTimes = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Console.WriteLine(ObtainFreeDayNum(int.Parse(summerVacationDaysAndHomeWorkNum[0]), homeWorkTimes));
            Console.Read();
        }

        private static int ObtainFreeDayNum(int summerVacation, int[] homeWorkTimes)
        {
            var freeDayNum = summerVacation - homeWorkTimes.Sum();

            if (freeDayNum < 0 )
            {
                return -1;
            }

            return freeDayNum;
        }
    }
}

Measured memory_bytes: 28908
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n,d;
    scanf("%d%d",&n,&d);
    int X[n][d];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < d;j++){
            scanf("%d",&X[i][j]);
        }
    }
    int count = 0;
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            int sum = 0;
            
                for(int k = 0;k < d;k++){
                    sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ans = sqrt((double)sum);
                if ((int)ans * (int)ans == sum){
                    count++;
                }
            
        }
    }

    printf("%d",count);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <math.h>
#include <vector> 
using namespace std;

 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }

    vector<int> max_ex(N);
    int true_max;
    true_max = A.at(0);
    for(int i=1;i<N;i++){
        true_max = max(true_max, A.at(i));
    }

    int count=0;
    for(int i=0;i<N;i++){
        if(A.at(i)==true_max){
            count++;
            if(count>1){
                for(int j=i;j<N;j++){
                    max_ex.at(j)=true_max;
                }
                break;
            }
            int sec_max=0;
            for(int j=0;j<N;j++){
                if(j==i){
                    continue;
                }
                sec_max = max(sec_max, A.at(j));
            }
            max_ex.at(i) = sec_max;
        }else{
            max_ex.at(i)=true_max;
        }
    }

    for(int i=0;i<N;i++){
        cout << max_ex.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
H, W, M = map(int, input().split())

#方針
# 1,基本的には、行和の最大と列和の最大の和が答えとなる
# 2,例外として、行和の最大を与える行と、列和の最大を与える列との交差点が、
#   全て爆破対象で埋まっている場合(飽和)、重複分の1を引く必要がある。

A = [0 for _ in range(H)] # 各行の爆破対象の個数 (行和)
B = [0 for _ in range(W)] # 各列の爆破対象の個数 (列和)
C = set() # 爆破対象の位置の集合

for _ in range(M): #入力処理
  h, w = map(int, input().split())
  A[h-1] += 1
  B[w-1] += 1
  C.add((h-1, w-1))

# 処理1, 行和の最大と列和の最大の和を求める
d = max(A) # 行和の最大
e = max(B) # 列和の最大
ans = d+e # 爆破できる最大の個数(仮)

# 処理2, 飽和を検出する
#  方針: 「交差点個数 == 交差点上の対象物個数」 なら飽和とする

F = set() # 最大を与える行の集合
G = set() # 最大を与える列の集合
for h in range(H):
  if A[h] == d:
    F.add(h)
for w in range(W):
  if B[w] == e:
    G.add(w)
  
spot = len(F)*len(G) # 最大を与える列と、最大を与える行の交差点の個数
bm_on_spot = 0 # 上記交差点の上にある対象物の個数 (以下のループ中でカウントする)
for c in C:
  if c[0] in F and c[1] in G: # 対象物が交差点上にある場合,カウント+1
    bm_on_spot += 1
    
if bm_on_spot == spot: #「交差点個数 == 交差点上の対象物個数」 なら飽和とする
  ans -= 1

print(ans)

Measured memory_bytes: 187564
def reach(s,t,G):
    V,E=G
    check=set()
    step=0
    nex={s}
    while nex!=set():
        if t in nex:
            return(step)
        else:
            check|=nex
            nex={v for v in V if v not in check and any([(v,w) in E for w in nex])}
            step+=1
    return(-1)

H,W=map(int,input().split())
S=[input() for i in range(H)]

point=0
sharp=0
V=set()
E=set()
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            point+=1
            V|={(i,j)}
            if i-1>=0:
                if S[i-1][j]=='.':
                    E|={((i,j),(i-1,j))}
            if i+1<=H-1:
                if S[i+1][j]=='.':
                    E|={((i,j),(i+1,j))}
            if j-1>=0:
                if S[i][j-1]=='.':
                    E|={((i,j),(i,j-1))}
            if j+1<=W-1:
                if S[i][j+1]=='.':
                    E|={((i,j),(i,j+1))}
        if S[i][j]=='#':
            sharp+=1
G=(V,E)

if reach((0,0),(H-1,W-1),G)==-1:print(-1)
else:print(point-(reach((0,0),(H-1,W-1),G)+1))

Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;



int main()
{
  ll n,k;
  cin >> n >> k;
  vector<int> s(n,0);

  for(int i=0; i<k;i++){
    int d;
    cin >> d;
    for(int j=0; j<d; j++){
      int a;
      cin >> a;
      a--;
      s.at(a)++;
    }
  }

  ll count =0 ;
  for(int i=0; i<n; i++){
    if(s.at(i)==0){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
  unsigned long long int a,b,c,d,c1,d1,leng,ans,x,y,r,tmp;
  scanf("%llu %llu %llu %llu",&a,&b,&c,&d);
  c1=c,d1=d;
  x=c*d;
  if(c<d){
    tmp = c;
    c = d;
    c = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = c % d;
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
  y=x/d;
  ans=(b-a+1)-(b/c1-(a-1)/c1)-(b/d1-(a-1)/d1)+(b/y-(a-1)/y);
  printf("%llu",ans);
  return 0;
}


Measured memory_bytes: 128