akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=6000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,maxd,f[N][N<<1],bas=6000;

namespace My_Math{
    #define N 100000

    int fac[N+100],invfac[N+100];

    int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
    int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
    int mul(int x,int y) {return 1ll*x*y%maxd;}
    ll qpow(ll x,int y)
    {
        ll ans=1;
        while (y)
        {
            if (y&1) ans=mul(ans,x);
            x=mul(x,x);y>>=1;
        }
        return ans;
    }
    int getinv(int x) {return qpow(x,maxd-2);}

    int C(int n,int m)
    {
        if ((n<m) || (n<0) || (m<0)) return 0;
        return mul(mul(fac[n],invfac[m]),invfac[n-m]);
    }

    void math_init()
    {
        fac[0]=invfac[0]=1;
        rep(i,1,N) fac[i]=mul(fac[i-1],i);
        invfac[N]=getinv(fac[N]);
        per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
    }
    #undef N
}
using namespace My_Math;

int main()
{
    n=read();maxd=read();
    f[0][bas]=1;
    rep(i,1,n*3)
    {
        rep(j,bas-i+1,bas+i-1)
        {
            f[i][j+1]=f[i-1][j];
            if (i>1) f[i][j-1]=add(f[i][j-1],mul(f[i-2][j],i-1));
            if (i>2) f[i][j]=add(f[i][j],mul(f[i-3][j],mul(i-1,i-2)));
        }
    }
    int ans=0;
    rep(i,bas,bas+n*3) ans=add(ans,f[n*3][i]);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 167628
#include <iostream>
#include <string>
#include <map>

int main()
{
	using i32 = std::int32_t;
	using str = std::string;
	using ch = str::value_type;

	i32 N;
	std::cin >> N;

	str S;
	std::cin >> S;

	std::map<ch, ch> convert;
	for (i32 i = 0; i < 26; ++i)
	{
		convert['A' + i] = 'A' + (i + N) % 26;
	}

	for (auto&& CH : S)
	{
		std::cout << convert[CH];
	}
	std::cout << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}
ll sq(int x) { ll ans = x*x ; return ans ; }

void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

// ==========Start Here==============

// 138 - 142
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 	
 	int n ; 
 	cin >> n ; 
 	vt<int> a(n) ; 
 	read(a) ; 
 	vt<int> ans(n) ; 
 	rep(i,0,n) {
 		ans[a[i]-1] = i + 1 ; 
 	}
 	rep(i,0,n) {
 		cout << ans[i] << " " ; 
 	}
	return 0 ; 
 	
}

Measured memory_bytes: 3968
n=int(input())
h=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

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

feasible = True
x = 0
y = 0
t = 0

for i in range(n):
    cp_t, cp_x, cp_y = map(int, input().split())
    if not feasible:
        continue

    step = abs(x - cp_x) + abs(y - cp_y)
    dt = cp_t - t
    if dt < step:
        feasible = False
    if (dt - step) % 2 != 0:
        feasible = False
    x = cp_x
    y = cp_y
    t = cp_t

if feasible:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	char ch[21];
	cin>>ch;
	int n=strlen(ch);
	char bch[n];
	int t=n-1;
	for(int a=0;a<n;a++){
		bch[t]=ch[a];
		t--;
	}
	for(int b=0;b<n;b++){
		printf("%c",bch[b]);
	}
	printf("\n");
}


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

int main(){
  string S;
  cin >> S;
  string a,b;
  a.push_back(S.at(0)); a.push_back(S.at(1));
  b.push_back(S.at(2)); b.push_back(S.at(3));
  int x = stoi(a);
  int y = stoi(b);
  if(0<x&&x<13&&0<y&&y<13){
    cout << "AMBIGUOUS" << endl;
  }else if(0<x&&x<13&&0<=y&&y<100){
    cout << "MMYY" << endl;
  }else if(0<=x&&x<100&&0<y&&y<13){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
alph = ('a'..'z').to_a + ('A'..'Z').to_a
index = Hash[*alph.zip((0..51).to_a).flatten]

loop {
    n = gets.to_i
    break if n == 0

    keys = gets.split(" ").map(&:to_i)
    s = gets.chomp

    keys.cycle.with_index{|k, i|
        break if i >= s.size
        s[i] = alph[(index[s[i]] - k) % 52] 
    }   
    puts s
}

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

int main() {
  int S, upper, lower;
  cin >> S;
  upper = S / 100;
  lower = S % 100;

  if (lower >= 1 && lower <= 12 && upper > 12) {
    cout << "YYMM" << endl;
  }
  else if (lower >= 1 && lower <= 12 && upper == 0) {
    cout << "YYMM" << endl;
  }
  else if (upper >= 1 && upper <= 12 && lower > 12) {
    cout << "MMYY" << endl;
  }
  else if (upper >= 1 && upper <= 12 && lower == 0) {
    cout << "MMYY" << endl;
  }
  else if (lower >= 1 && lower <= 12 && upper >= 1 && upper <= 12) {
    cout << "AMBIGUOUS" << endl;
  }
  else {
    cout << "NA" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,n,i,c;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    c=n/2;
    //cout<<a[c+1]<<a[c];
    d=a[c]-a[c-1];
    cout<<d<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		//long n = sc.nextLong();

		/*if((a+b)%3==0 || a%3==0 || b%3==0) {
			System.out.println("Possible");
		}else {
			System.out.println("Impossible");
		}*/
		System.out.println("ABC"+s);
	}
}




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

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (t > s)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int N, M, R;
vector<vector<int>> d(300, vector<int>(300, 1e9));

void warshall_floyd() {
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        int x;
        cin >> x;
        r[i] = x - 1;
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd();
    int ans = 1e9;
    sort(r.begin(), r.end());
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += d[r[i]][r[i + 1]];
        }
        ans = min(ans, sum);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e9;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second


int main(){
    //freopen("input00.txt","r",stdin);
    ll T = 1;
    //cin>>T;
    while(T--){
        string s;
        ll  n ,p;
        cin>>n>>p;
        cin>>s;

        if(p==2){
            ll ANS=0;
            for(ll i=0;i<s.size();i++){
                if((s[i]-'0')%2==0 )
                    ANS += i+1;
            }
            cout << ANS;
            continue;
        }

        if(p==5){
            ll ANS=0;
            for(ll i=0;i<s.size();i++){
                if((s[i]-'0')%5==0){
                    ANS += i+1;
                }
            }
            cout << ANS ;
            continue;
        }
        ll ANS=0;
        ll N = 0;
        map<ll,ll> MAP;
        MAP[0]++;
        ll mf=1;
        for(ll i=n-1;i>=0;i--){
            N = (N + (s[i] - '0')*mf)%p;
            ANS += MAP[N];
            MAP[N]++;
            mf  = (mf*10)%p;
        }

        cout << ANS;
    }

    return 0;
}

Measured memory_bytes: 1028
a,b,k = gets.split.map(&:to_i)
turn = 0
k.times do
  if turn == 0
    b = b + a/2
    a = a/2
    turn = 1
  elsif turn == 1
    a = a + b/2
    b = b/2
    turn = 0
  end
#  puts ("#{a} #{b}")
end
puts ("#{a} #{b}")


Measured memory_bytes: 1788
N=int(input())
A=list(map(int, input().split()))
ans=[max(A)]

k=ans[0]
n=-1
for i in range(N):
    if abs(A[i]-ans[0]/2) < k and A[i] != ans[0]:
        k=abs(A[i]-ans[0]/2)
        n=i
ans.append(A[n])
        
print(*ans)

Measured memory_bytes: 14428
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<ldouble, ldouble> pdd;

char A[20];

void solve() {
	scanf("%s", A);
	int l = (int)strlen(A);
	int ok = 1;
	for(int i=1;i<l;i++) if(A[i] != '9') ok = 0;
	int s = A[0] - '0' + 9 * (l - 1);
	if(ok == 0) --s;
	printf("%d\n", s);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 2010;
int n, b[maxn], w[maxn], dp[maxn][maxn], costb[maxn][maxn], costw[maxn][maxn];
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=2*n; i++) {
		char c;
		int x;
		cin>>c>>x;
		if(c == 'B') b[x] = i;
			else w[x] = i;
	}
	memset(dp, 0x3f, sizeof(dp));
	for(int i=1; i<=n; i++) {
		for(int j=1; j<i; j++) 
			if(b[j] > b[i]) costb[i][0]++;
		for(int j=1; j<=n; j++)
			if(w[j] > b[i]) costb[i][j] = costb[i][j-1] + 1;
				else costb[i][j] = costb[i][j-1];
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<i; j++) 
			if(w[j] > w[i]) costw[i][0]++;
		for(int j=1; j<=n; j++)
			if(b[j] > w[i]) costw[i][j] = costw[i][j-1] + 1;
				else costw[i][j] = costw[i][j-1];
	}
	dp[0][0] = 0;
	for(int i=0; i<=n; i++)
		for(int j=0+(i == 0); j<=n; j++) {
			if(i) dp[i][j] = min(dp[i][j], dp[i-1][j] + costb[i][j]);
			if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] + costw[j][i]);
		}
	printf("%d\n", dp[n][n]);
	return 0;
}

Measured memory_bytes: 47744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		int i = 0;
		while (i == 0) {
			String line = sc.nextLine();
			String[] x = line.split(" ");
			int H = Integer.parseInt(x[0]);
			int W = Integer.parseInt(x[1]);
			if (H == 0 && W == 0) {
				break;
			}
			String nakami = "";
			String jouge = "##";
			int j = 0;
			while (j < W - 2) {
				nakami += ".";
				jouge += "#";
				j++;
			}
			String yoko = "#" + nakami + "#";
			int k = 0;
			while (k < H) {
				if (k == 0 || k == H - 1) {
					System.out.println(jouge);
				} else {
					System.out.println(yoko);
				}
				k++;
			}
			System.out.println("");

		}
	}

}

Measured memory_bytes: 27340
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  // const int64_t L = static_cast<int64_t>(T.length());
  int64_t A, B;
  cin >> A >> B;
  cout << (A*B) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int a,b,k;
  cin>>a>>b>>k;
  FOR(i,a,b+1) {
    if(i < a + k || i > b - k) {
      cout << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

import heapq


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()

if N%2 == 1:
  for i in range(M):
    if i%2 == 0:
      print(i//2+2,N-i//2)
    if i%2 == 1:
      print(N//2-i//2+1,N-(N//2-i//2)+1)
      
if N%2 == 0:
  for i in range(M):
    if i%2 == 0:
      print(i//2+1,N-i//2)
    if i%2 == 1:
      print(N//2-i//2,N-(N//2-i//2)+2)

Measured memory_bytes: 79468
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

bool is_kaibun(const std::string& s)
{
  int n = static_cast<int>(s.size());
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - i - 1]) return false;
  }
  //std::cerr << "true" << std::endl;
  return true;
}

std::string solve(const std::string& s)
{
  int n = static_cast<int>(s.size());
  if (!is_kaibun(s)) return "No";
  if (!is_kaibun(s.substr(0, (n - 1) / 2))) return "No";
  if (!is_kaibun(s.substr((n + 3) / 2 - 1))) return "No";
  return "Yes";
}

int main()
{
  std::string s;
  std::cin >> s;

  std::cout << std::setprecision(20);
  std::cout << solve(s) << std::endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


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

	a -= c;
	b = b+c;
	cout << a/b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	int k;
	cin >> k;
	long long ans = 0;
	for(int i = 1; i <= k; i++)
		for(int j = 1; j <= k; j++)
			for(int l = 1; l <= k; l++)
				ans += __gcd(__gcd(i, j), l);
	cout << ans;
}      

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
	int N;
	cin >> N;
	VI d(N);
	rep(i, 0, N) scanf("%d", &d[i]);
	sort(ALL(d));

	int counter = 1;
	rep(i, 0, N-1) {
		if (d[i] < d[i+1]) ++counter;
	}
	cout << counter << "\n";


	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#define inf 1000000
using namespace std;
long long int p[114514],x,y,z,w;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			if(p[x]>=inf) continue;
			p[x]+=y*z;
			if(p[x]>=inf) f=1,cout<<x<<endl;
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a==b) puts("0");
	else{
		if((a+b)%2==0) printf("%d\n",(a+b)>>1);
		else puts("IMPOSSIBLE");
	}
	return 0;
}
/*
a-c=b-c
a-c=c-b
c-a=b-c
c-a=c-b
*/


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int x,y;
	scanf("%d %d",&x,&y);
	
	if(x==y){printf("a == b\n");}
	if(x>y){printf("a > b\n");}
	if(x<y){printf("a < b\n");}
	
	return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main(){
  int n, k;
  cin >> n >> k;

  if((n-1)*(n-2)/2 < k){
    cout << -1 << endl;
    return 0;
  }

  vector<pii> ans;
  rep(i, 1, n){
    ans.pb({0, i});
  }

  int cnt = (n-1)*(n-2)/2 - k;
  [&](){
    rep(i, 1, n){
      rep(j, i+1, n) if(cnt){
        ans.pb({i, j});
        cnt--;
      }
    }
  }();

  cout << ans.size() << endl;
  for(auto i : ans){
    cout << i.first+1 << " " << i.second+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < s.size(); i += n) {
        cout << s[i];
    }
    cout << '\n';
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main(){
    int n, tp=0, hp=0;
    cin >> n;
    string ts, hs;
    rep(i, n){
        cin >> ts >> hs;
        if(ts==hs){
            tp++;
            hp++;
        }else if(ts>hs){
            tp += 3;
        }else{
            hp += 3;
        }
    }
    cout << tp << ' ' << hp << endl;
    
    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int INF=1e9;
int s,n,m,t,p;
int x[2000];
vector<int> A;
int dp[2005][2005];
int mem[2005][2005];

int main(){
  scanf("%d %d %d",&s,&n,&m);
  for(int i=0;i<s;i++)scanf("%d",&x[i]);
  for(int i=0;i<n;i++){
    scanf("%d %d",&t,&p);
    A.push_back(t-x[p-1]);
  }
  A.push_back(-INF);
  sort(A.begin(),A.end());
  A[0]=0;

  int size=A.size()-1,base=A[1];
  for(int i=1;i<=size;i++)A[i]-=base;
  fill(dp[1],dp[2005],1e9);
  for(int i=1;i<=size;i++){ 
    for(int j=1;j<=m;j++){
      int sum=0;
      for(int k=i-1;k>=mem[i][j-1];k--){
        if(dp[i][j]>dp[k][j-1]+sum){
          dp[i][j]=dp[k][j-1]+sum;
          mem[i][j]=k;
        }
        sum+=(A[i]-A[k]);
        //if(sum>dp[i][j])break;
      }
    }
  }
  cout<<dp[size][m]<<endl;
  return 0;
}

Measured memory_bytes: 32624
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const ld PI = (ld)acos(-1);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
    ll N,M,V,P;
    cin>>N>>M>>V>>P;
    vector<ll>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end(),greater<ll>());
    ll right=N;
    ll left=0;
    while(right-left>1){
        ll mid=(right+left)/2;
        //midでできる個数を調べていく
        vector<ll>num(N,0);
        if(A[mid] + M < A[P-1]){
            right=mid;
            continue;
        }
        if(mid<P){
            //true
            left=mid;
            continue;
        }
        ll a = (P-1)*M;
        REP(j, P-1, N) {
            if (j >= mid) {
                a += M;
            } else {
                a += A[mid] + M - A[j];
            }
        }
        if(a>=M*V)left=mid;
        else right=mid;

    }
    cout<<right<<endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n){cin >> a[i];}

    int b = 0;
    rep(i, n){
        if(a[i]!=i+1) b++;
    }
    if(b>2)out("NO");
    else out("YES");
}

Measured memory_bytes: 3628
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
  int a,d=0;
  string s;
  cin>>a>>s;
  for(int i=0;i<a;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      d++;
    }
  }
  std::cout << d << std::endl;
    return 0;
}


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

typedef long long llong;
// -2.1e-9 <= int <= 2.1e9

int main()
{
    int N, M;
    cin >> N >> M;
    vector<bool> state(N+1, false);
    vector<int> histWA(N+1, 0);

    int numAC = 0;
    int numWA = 0;
    for (int i=1; i<=M; i++) {
        size_t pi; string Si;
        cin >> pi >> Si;

        if (state[pi] == false) {
            if (Si == "AC") {
                ++numAC;
                numWA += histWA[pi];
                state[pi] = true;
            }
            else if (Si == "WA") {
                ++histWA[pi];
            }
        }
    }
    cout << numAC << ' ' << numWA << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define vel vector<long long>
#define veb vector<bool>
#define vvel vector<vel>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)
using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    int n;
    cin >> n;
    vel h(n);
    rep(i, n){ cin >> h[i]; }
    int count = 0;
    rep(i, n){
        if(i == 0){
            count++;
            continue;
        }
        if(h[i] >= maxel(h, i)){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int main() {
#define int long long
	long long n, k;
	cin >> n >> k;
	vector<long long> A;
	REP(i, n) {
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int q = 0; q < n; ++q) {
			if (i == q) continue;
			if (i < q) {
				if (A[i] > A[q]) {
					ans += k * (k + 1LL) / 2LL;
					ans %= MAX_MOD;
				}
			}
			else {
				if (A[i] > A[q]) {
					ans += k * (k - 1LL) / 2LL;
					ans %= MAX_MOD;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

// #define N 50005


int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    int n,a,b;
    cin >> n >> a >> b;



    vector<int> ai[3];
    rep(i,n) {
        int aa;
        cin >> aa;
        // cin >> a[i];
        if(aa <= a) ai[0].pb(1);
        else if(aa > a and aa <= b) ai[1].pb(1);
        else ai[2].pb(1);
    }

    int ans = min({sz(ai[0]), sz(ai[1]), sz(ai[2])});

    cout << ans << "\n";


}

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

int main() {
  int a, b , c ,d,L,R ;
  
  cin >> a  >> b >> c >> d >> L >>R;
L = a + b;
  R = c + d;
 if(L > R){
 cout << "Left" << endl;
 }
  else if(L == R){
  cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
  
  
}

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

int n,m,mx=0;
string s, t;
map<string,int> cards;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		cards[s]++;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>t;
		cards[t]--;
	}
	for(auto it=cards.begin();it!=cards.end();++it){
		if(it->second > mx)
			mx = it->second;
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define ll long long
  
int main(){
    string s,t;
    cin>>s>>t;
    int flag=0;
    rep(i,0,s.length()){
        if(s[i]!=t[i])flag=1;
    }
    if(flag==0 && s.length()+1==t.length()){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
 
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>

#define rep(i, a) for (int i = 0; i < (a); i++)

using namespace std;

int main(void) {
  int a,b,k;
  cin >> a >> b >> k;
  vector<int> v;
  for (int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  cout << v[v.size() - k] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int C[N], S[N], F[N];
  for (int i=0 ; i<N-1 ; i++) scanf("%d %d %d", &C[i], &S[i], &F[i]); 
  int res;
  for (int i=0 ; i<N ; i++) {
    res = 0;
    for (int j=i ; j<N-1 ; j++) {
      if (S[j] >= res) res += S[j] - res + C[j];
      else if (res%F[j] == 0) res += C[j];
      else res += F[j] - res%F[j] + C[j];
    }
    printf("%d\n", res);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> Zalgo(string str) {
	int n = str.size();
	vector<int> a(n, 0);
	int from = -1, last = -1;
	for (int i = 1; i < n; ++i) {
		int &same = a[i];
		if (from != -1) {
			same = min(a[i - from], last - i);
			maxs(same, 0);
		}
		while (i + same < str.size() && str[same] == str[i + same]) same++;
		if (last < i + same) {
			last = i + same;
			from = i;
		}
	}
	for (int i = 1; i < n; ++i) {
		mins(a[i], i);
	}
	a[0] = n;
	return a;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		string tmp = s.substr(i);
		auto rec = Zalgo(tmp);
		for (int j = 1; j < rec.size(); ++j) {
			maxs(ans,rec[j]);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



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

    for (int i = 0; i < n; i++)cin >> p[i];
    for (int i = 0; i < n; i++)cin >> b[i];
    vector<int>t(n);
    t = p;
    sort(t.begin(), t.end());
    long long int x = 0, y = 0, z = 0;
    do{
        z++;
        if (t == p)x = z;
        if (t == b)y = z;

    }while(next_permutation(t.begin(), t.end()));

    cout << abs(x - y) << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int a[101][101];
int main()
{
	//freopen("mine.in","r",stdin);
	//freopen("mine.out","w",stdout);
	int n,m;
	char s[101][101];
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>s[i][j];
			if(s[i][j]=='#') a[i][j]=1;
		}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='#')
			{
                cout<<"#";
            }
            else
			{
                cout<<a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1];
	        }  
        }
		cout<<endl;
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

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

B1 = []
B2 = []
for i, a in enumerate(A):
    B1.append(a-i)
    B2.append(-a-i)

dic = {}

ans = 0
for b1, b2 in zip(B1, B2):
    if b1 in dic:
        ans += dic[b1]
    if b2 in dic:
        dic[b2] += 1
    else:
        dic[b2] = 1

print(ans)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> idx(200001, -1), next(n, -1);
  rep(i, n) {
    int c;
    cin >> c;
    if (idx[c] != -1) next[idx[c]] = i;
    idx[c] = i;
  }

  vector<ll> dp(n + 1, 0);
  dp[0] = 1;
  rep(i, n) {
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    if (next[i] != -1 && next[i] != i + 1) dp[next[i]] = dp[i];
  }

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


Measured memory_bytes: 3456
S = input().strip()
op = ["+","-"]
ind = 0
for op1 in op:
    for op2 in op:
        for op3 in op:
            if eval(S[0]+op1+S[1]+op2+S[2]+op3+S[3])==7:
                print(S[0]+op1+S[1]+op2+S[2]+op3+S[3]+"=7")
                ind = 1
                break
        if ind==1:break
    if ind==1:break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back

using namespace std;

void  dfs(vector <int> a[][2],int i,bool visited[],ll value[])
{
	stack <int> s;
	s.push(i);
	
	
	while(!s.empty())
	{
		int p=s.top();
		s.pop();
		
		for(int j=0;j<a[p][0].size();j++)
		{
			if(!visited[a[p][0][j]])
			{
				s.push(a[p][0][j]);
				visited[a[p][0][j]]=true;
				value[a[p][0][j]]=value[p]+a[p][1][j];
				dfs(a,a[p][0][j],visited,value);
			}
		}
	}
}

int main()
{
	ll n,m;
	cin>>n>>m;
	ll  l[m+1],r[m+1],d[m+1];
	vector <int> a[n+1][2];
	ll value[n+1];
		
	for(int i=1;i<=m;i++)
	{
		cin>>l[i]>>r[i]>>d[i];
		a[l[i]][0].pb(r[i]);
		a[l[i]][1].pb(d[i]);
		a[r[i]][0].pb(l[i]);
		a[r[i]][1].pb(-d[i]);
	}
	
	bool visited[n+1]={0};
	
	//dfs
	
	for(int i=1;i<=n;i++)
	{
		if(!visited[i]) {value[i]=0; dfs(a,i,visited,value);}
	}	
	bool b=1;
	for(int i=1;i<=m;i++)
	{
		if(value[r[i]]-value[l[i]]!=d[i]) {b=0; break;}
	}
	
	if(b) cout<<"Yes\n";
	else cout<<"No";
	
}


Measured memory_bytes: 93952
#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int N,M,sum = 0,nmax = 0;
    cin>>N>>M;
    for(int i = 0 ; i < M; i++){
        int A,B;
        cin>>A>>B;
        int okane = max (N-A,0);
        if( okane > nmax ) nmax = okane;
        sum+=okane;
        
        
    }
    cout << sum - nmax << endl;
    

    return 0;
}



Measured memory_bytes: 3092
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))

Measured memory_bytes: 8668
#include <iostream>                                                      
using namespace std;                                                     
                                                                         
int main() {                                                             
  while (true) {                                                         
    int m, f, r;                                                         
    cin >> m >> f >> r;                                                  
    if (m+f+r==-3) {                                                     
      break;                                                             
    }                                                                    
    int x = m+f;                                                         
    char ans;                                                            
    if (m==-1 || f==-1) {                                                
      ans = 'F';                                                         
    } else if (x>=80) {                                                  
      ans = 'A';                                                         
    } else if (x>=65) {                                                  
      ans = 'B';                                                         
    } else if (x>=50) {                                                  
      ans = 'C';                                                         
    } else if (x>=30) {                                                  
      if (r>=50) {                                                       
        ans = 'C';                                                       
      } else {                                                           
        ans = 'D';                                                       
      }                                                                  
    } else {                                                             
      ans = 'F';                                                         
    }                                                                    
    cout << ans << endl;                                                 
  }                                                                      
  return 0;                                                              
}                   

Measured memory_bytes: 3060
N=int(input())

A = []

for i in range(N):
    A.append(int(input()))

count=0    
prev_wait = 0
for i in range(N):
    if A[i]>=1:
        count+=int((prev_wait+A[i])/2)
        prev_wait = (A[i]+prev_wait)%2
    else:
        prev_wait = 0
        
print(count)

Measured memory_bytes: 7072
import sys
from math import factorial


def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    # [x,y]
    return [w[0], w[1]]


# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m

def nCr(n, r, mod):
    a = factorial(r)
    b = 1
    for i in range(1, r + 1):
        b = b * (n - i + 1) % mod
    a = mod_inv(a, mod)
    return b * a

n, a, b = [int(i) for i in sys.stdin.readline().split()]
mod = 10 ** 9 + 7
res = 2 ** n % mod
res -= (nCr(n, a, mod) + nCr(n, b, mod) + 1) % mod
if res < 0:
    res += mod
print(res)

Measured memory_bytes: 156828
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] T = new int[N];
    for(int i=0; i<N; i++){
      T[i] = sc.nextInt();
    }
    int sum = 0;
    for(int i=0; i<N-1; i++){
      for(int j=i+1; j<N; j++){
        sum += T[i]*T[j];
      }
    }
    System.out.print(sum);
  }
}

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

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = 0;
		int i = 0;
		int n = 0;
		int w = 0;
		while(w==0){
			s = sc.nextInt();
			if(s==0){
				break;
			}
			int[] a = new int[s];
			for(i=0;i<s;i++){
				a[i] = sc.nextInt();
			}
			Arrays.sort(a);
			for(i=1;i<s-1;i++){
				n = n + a[i];
			}
			n = n/(s-2);
			System.out.println(n);
			s = 0;
			i = 0;
			n = 0;
			w = 0;
		}
	}
}

Measured memory_bytes: 20944
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll dp[100004][2];
ll a[100004];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	dp[2][0]=a[1]+a[2];
	dp[2][1]=-(a[1]+a[2]);
	for (int i=3;i<=n;i++){
		dp[i][0]=max(dp[i-1][0],dp[i-1][1])+a[i];
		dp[i][1]=max(dp[i-1][0]-2*a[i-1]-a[i],dp[i-1][1]+2*a[i-1]-a[i]);
	}
	cout<<max(dp[n][0],dp[n][1]);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,b,c;
   cin >> a >> b >> c;
   cout << a+b+c + max({a,b,c})*9 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using pint = pair<int, int>;
using pll = pair<ll,ll>;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

map<ll,int> divisor;
void test(ll x){
    ll num = sqrt(x);
    for(int i=1;i<num+1;i++){
        if(x%i==0){
            divisor[x/i]++;
            divisor[i]++;
        }
    }
}
bool prime(ll n){
  int n_root = sqrt(n);
  if(n==1)return 1;
  else if(n==2)return true;
  else if (n%2==0)return false;
  for(int i=3;i<n_root+1;i+=2){
    if(n%i==0)return false;
  }
  return true;
}

int main(){
    ll a,b;
    cin >> a >> b;
    if(a==1||b==1){
        COUT(1);
        return 0;
    }
    test(a);test(b);
    vector<ll>vec;
    for(const auto &x:divisor){
        if(x.second==2){
            vec.push_back(x.first);
        }
    }
    int count = 0;
    for(ll x:vec){
        if(prime(x)==1){
            count++;
        }
    }
    COUT(count);
    return 0;
}

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

int main(){
    ll a,b; cin >> a >> b;
    if(a > 0 && b > 0) cout << "Positive" << endl;
    else if(a*b <= 0) cout << "Zero" << endl;
    else if((a-b) % 2 == 0) cout << "Negative" << endl;
    else cout << "Positive" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (200000)

int N;
ll A[MAX_N];

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	ll tot = 0;
	FOR(n,N) {
		cin >> A[n];
		tot+=A[n];
	}
	ll ar=0;
	ll al=0;
	int n=0;
	for(;n<N;n++) {
		al= ar;
		ar+=A[n];
		if(tot%2!=0) {
			if(ar>tot/2) {
				break;
			}
		}
		else {
			if(ar>=tot/2) {
				break;
			}
		}
	}
	int l = n-1;
	int r = n;
	if(tot%2==0&&tot/2==ar) {
		cout<<0<<endl;
		return 0;
	}
	DOUT<<"tot=="<<tot<<endl;
	DOUT << "l="<<l<<",r="<<r<<endl;
	DOUT << "al=="<<al<<", ar=="<<ar<<endl;
	DOUT << "tot-2*al=="<<(tot-2*al)<<endl;
	DOUT << "2*ar-tot=="<<(2*ar-tot)<<endl;
	ll mindiff = min((tot-2*al),(2*ar-tot));
	cout << mindiff <<endl;

	return 0;
}




Measured memory_bytes: 1792