akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

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

    for(int i = a; i <= a * b; i += a) {
        if(i % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 * C - 怪文書 / Dubious Document
 * https://atcoder.jp/contests/abc058/tasks/arc071_a
 **/
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main() {
    int n; cin >> n;
    string alphabets = "abcdefghijklmnopqrstuvwxyz";
    map<char, int> m;
    for(int i=0; i<n; i++) {
        // O(N)
        map<char, int> tmp;
        string si; cin >> si;
        for(auto c:si) {
            if(tmp.count(c)==0) {
                tmp[c] = 1;
            } else {
                tmp[c] += 1;
            }
        }
        for(auto a:alphabets) {
            // O(26)
            if(m.count(a)==0) {
                m[a] = tmp[a];
            } else {
                m[a] = min(m[a], tmp[a]);
            }
        }
    }
    for(auto ci:m) {
        for(int i=0; i<ci.second; i++) cout << ci.first;
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
 
namespace ALDS1_14_D
{
    class SuffixArray
    {
        internal int[] sa, rank, tmp;
        internal string S;
        internal int n, k;
         
        public SuffixArray(string SS)
        {
            S = SS;
            n = S.Length;
            sa = new int[n + 1];
            rank = new int[n + 1];
            tmp = new int[n + 1];
            Construct_SA();
        }
         
        public int Compare_SA(int i, int j)
        {
            if(rank[i] != rank[j]) return rank[i] - rank[j];
             
            int ri = i + k  <= n ? rank[i + k] : -1;
            int rj = j + k <= n ? rank[j + k] : -1;
 
            return  ri - rj; 
        }
         
        public void Construct_SA()
        {
            for(int i = 0; i < n; i++)
            {
                sa[i] = i;
                rank[i] = S[i];
            }
            sa[n] = n; rank[n] = -1;
             
            for(k = 1; k <= n; k*= 2)
            {
                Array.Sort(sa, Compare_SA);
                 
                int d;
                d = tmp[sa[0]] = 0;
                for (int i = 1; i <= n; i++)
                {
                    d = tmp[sa[i]] = d + ((Compare_SA(sa[i - 1], sa[i]) < 0) ? 1 : 0);
                }
                for (int i = 0; i <= n; i++)
                {
                    rank[i] = tmp[i];
                }
  
            }
        }
         
        public string Contains(string pattern)
        {
            int l = 1, r = n + 1;
            int pl = pattern.Length;
             
            while(l < r)
            {
                int m = (l + r) / 2;
                 
                string subStr = (sa[m] + pl > n) ? S.Substring(sa[m]) : S.Substring(sa[m], pl);
                     
                int comp = subStr.CompareTo(pattern);
                if (comp == 0) return "1";
                 
                if (comp < 0) l = m + 1;
                else r = m;
            }
            return "0";
        }
    }
     
     
    class Program
    {
         
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
          
            var T = Console.ReadLine();
             
            var SA = new SuffixArray(T);
 
  
            var Q = int.Parse(Console.ReadLine());
  
            for (int i = 0; i < Q; i++)
            {
                var P = Console.ReadLine();
  
                Console.WriteLine(SA.Contains(P));
            }
            sw.Flush();
        }
    }
}

Measured memory_bytes: 34240
#include <stdio.h>
#include <math.h>

#define RMAX pow(10, 9)
#define RMIN 1

int main (void) {
    int n, r, rmin=2*RMAX;
    int res = RMIN-RMAX-1;

    scanf ("%d", &n);

    for (int i=0; i<n; i++) {
        scanf ("%d", &r);
        if (res < r-rmin) res = r-rmin;
        if (r < rmin) rmin = r;
    }

    printf ("%d\n", res);
    
    return 0;
}


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

count = 0

if N == 1 and M == 1:
    count = 1
elif N == 1:
    count = M - 2
elif M == 1:
    count = N - 2
else:
    count = (M - 2) * (N - 2)

print(count)

Measured memory_bytes: 2940
package main
  
import (
    "fmt"
)

func main() {
    var s []byte
    fmt.Scan(&s)
    var cnt int
    var ps []byte
    var pb byte
    pb = ' '

    for _, b := range s {
        if pb == ' ' {
            if len(ps) > 1 {
                ps = []byte{b}
                cnt++
            } else {
                if len(ps) == 0 || b != ps[0] {
                    ps = []byte{b}
                    cnt++
                } else {
                    pb = b
                }
            }
        } else {
            ps = []byte{pb, b}
            cnt++
            pb = ' '
        }
    }

    fmt.Println(cnt)
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	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(ll t) const{
		if (!t) return 1;
		mint a=pow(t>>1);
		a*=a;
		if(t&1) a*=*this;
		return a;
	}
	// for prime mod
	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;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	mint x=0,y=0;
	rep(i,n){
		mint a;
		cin>>a;
		x+=a*(2*i-n+1);
	}
	rep(i,m){
		mint b;
		cin>>b;
		y+=b*(2*i-m+1);
	}
	mint ans=x*y;
	cout<<ans<<endl;
}

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

int main()
{
    int maxh,n,h0,h,t=1;
    cin>>n;
    cin>>h0;
    maxh=h0;
    n--;
    while(n--)
    {
        cin>>h;
        if(h>=maxh)
        {
            t++;
            maxh=h;
        }
    }
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll H, W;
  cin >> H >> W;

  if (H == 1 or W == 1) {
    cout << 1 << endl;
    return;
  }

  ll foo = (W + 1) / 2;
  ll bar = W / 2;

  ll x =  (H + 1) / 2;
  ll y = H / 2;

  ll ans = foo * x + bar * y;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
vector<vector<int> > g;

void saiki(int a,int b,int lev){
    if(a>=b)return;
    int mid = (a+b)/2;
    for(int i=a;i<=mid;i++){
        for(int j=mid+1;j<=b;j++){
            g[i][j] = lev;
        }
    }
    saiki(a,mid,lev+1);
    saiki(mid+1,b,lev+1);
}

int main(){
    int n;
    cin >> n;
    g.resize(n+1);
    rep(i,n+1){
        g[i].resize(n+1);
    }
    saiki(1,n,1);
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
typedef unsigned long long ll;
int ctoi(char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(){
    ll a;
    double b;
    cin >> a >> b;
    string s = to_string(b);
    char o = s.at(0);
    char p = s.at(2);
    char q = s.at(3);
    int va = 100*ctoi(o)+10*ctoi(p)+ctoi(q);
    cout << a*va/100 << endl;

}

Measured memory_bytes: 3828
#include <iostream>
using namespace std;
typedef long long ll;
ll h, w, mn;
ll f(ll p, ll q, ll r) {
	ll x = max(p, max(q, r));
	ll y = min(p, min(q, r));
	return min(mn, x-y);
}

int main() {
	cin>>h>>w;
	mn = h*w%3 ? min(h,w): 0;
	for(ll i=1; i<h; i++) mn = f(i*w, (h-i)*(w/2), (h-i)*(w-w/2));
	for(ll i=1; i<w; i++) mn = f(i*h, (w-i)*(h/2), (w-i)*(h-h/2));
	cout<<mn;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> r(n+1),g(n+1),b(n+1);
    for(int i=1;i<=n;i++){
        r[i] += r[i-1];
        g[i] += g[i-1];
        b[i] += b[i-1];
        switch(s[i-1]){
            case 'R':r[i]++;break;
            case 'G':g[i]++;break;
            case 'B':b[i]++;break;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] == s[j]) continue;
            if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) ans += b[n] - b[j];
            if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) ans += g[n] - g[j];
            if((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) ans += r[n] - r[j];
            if(j+(j-i) < n && (s[i] != s[j+(j-i)] && s[j] != s[j+(j-i)])) ans --;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	static int bord[][];
	static int ans;
	static int mx[]={-1,0,1,0};
	static int my[]={0,-1,0,1};
	static int sx,sy,gx,gy,w,h;

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int i,j;
		while(true){
			w=sc.nextInt();
			h=sc.nextInt();
			if(w+h==0) break;
			bord=new int[h][w];
			ans=-1;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					bord[i][j]=sc.nextInt();
					if(bord[i][j]==2){
						sx=j;
						sy=i;
					}
					if(bord[i][j]==3){
						gx=j;
						gy=i;
					}
				}
			}
			dfs(sx,sy,1);
			System.out.println(ans);
		}
	}//main

	static void dfs(int x,int y,int k){
		int nx,ny,i;
		boolean flag;
		if(10<k) return;
		for(i=0;i<4;i++){
			nx=x+mx[i];
			ny=y+my[i];
			flag=true;
			if(0<=nx && nx<w && 0<=ny && ny<h && bord[ny][nx]!=1){
				if(nx==gx && ny==gy){
					if(ans==-1 || k<ans)
						ans=k;
					return;
				}
				while(true){
					nx=nx+mx[i];
					ny=ny+my[i];
					if(0<=nx && nx<w && 0<=ny && ny<h){
						if(nx==gx && ny==gy){
							if(ans==-1 || k<ans)
								ans=k;
							return;
						}
						if(bord[ny][nx]==1){
							break;
						}
					}
					else{
						flag=false;
						break;
					}
				}
				if(flag){
					bord[ny][nx]=0;
					dfs(nx-mx[i],ny-my[i],k+1);
					bord[ny][nx]=1;
				}
			}
		}
	}

}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m, i, s = 0, sum;
		int t[] = new int[100];
		
		n = sc.nextInt();
		for(i = 0; i < n; i++){
			t[i] = sc.nextInt();
			s += t[i];
		}
		m = sc.nextInt();
		
		for(i = 0; i < m; i++){
			sum = (s - t[sc.nextInt() - 1]) + sc.nextInt();
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll mod=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------

int main(){
	int r; cin >> r;
	cout << 3* r* r << endl;
    return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int p = count(s.begin(), s.end(), 'p');
	int g = count(s.begin(), s.end(), 'g');
	cout << (p + g) / 2 - p << endl;
}


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

using namespace std;

using ll = long long;

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

    string s;
    cin >> s;
    int idx_a = 0, idx_z = 0;

    for (size_t i = 0; i < s.size(); ++i)
        if (s[i] == 'A') { idx_a = i; break; }
    for (size_t i = 0; i < s.size(); ++i)
        if (s[i] == 'Z') idx_z = i;

    cout << idx_z - idx_a + 1 << endl;

    return 0;
}


Measured memory_bytes: 720
N = int(input())
s = []
l = []
p = []
for _ in range(N):
	temp_s,temp_l,temp_p = map(int,input().split())
	s.append(temp_s)
	l.append(temp_l)
	p.append(temp_p)

M = int(input())
w = [int(input()) for _ in range(M)]

max_M = max(w)

dp = [[-1 for _ in range(max_M + 1)] for _ in range(N+1)]

for i in range(N):
	for j in range(s[i],min(l[i]+1, max_M+1)):
		dp[i+1][j] = p[i]

for i in range(N):
	for j in range(max_M+1):
		if j < s[i]:
			dp[i+1][j] = max(dp[i+1][j], dp[i][j])
		elif j >= s[i]:
			if dp[i+1][j-s[i]] == -1:
				dp[i+1][j] = max(dp[i+1][j], dp[i][j])
			else:
				dp[i+1][j] = max(dp[i+1][j], dp[i][j], dp[i+1][j-s[i]] + p[i])
				

ans = []
for i in range(M):
	ans.append(dp[N][w[i]])

if ans.count(-1) >= 1:
	print(-1)
else:
	for a in ans:
		print(a)



Measured memory_bytes: 6924
def resolve():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    while True:
        mini = a[0]
        others = a[1:]
        others = [x % mini for x in others]
        if sum (others) == 0:
            print(a[0])
            exit()
        a = [mini] + others
        a =[i for i in a if i!= 0]
        a = sorted(a)
resolve()

Measured memory_bytes: 75416
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
    int ret = 1; while (b > 0) {
        if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
    } return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
    return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    return ret;
}
Mat fastpow(Mat x, ll n)
{
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N; ll K; int A[50][50];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) rep(j, 0, N) cin >> A[i][j];

    Mat m(N, Vec(N, 0));
    Vec v(N, 1);

    rep(i, 0, N) rep(j, 0, N) m[i][j] = A[i][j];
    m = fastpow(m, K);
    v = mulMatVec(m, v);

    ll ans = 0;
    rep(i, 0, N) ans += v[i];
    ans %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 384
#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, m;
	cin >> n >> m;
	string p;
	cin >> p;

	vector<int>a(n+1), b(n+1);
	for (int i = 1; i < n; i++) {
		if (p[i] == 'C'&&p[i-1] == 'A')b[i]++;
	
		b[i + 1] = b[i];
//		cout << a[i];
	}
	
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << (b[y] - b[x]) << endl;
	}

	return 0;

}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    int l=0,r=m+(!(m&1))+1;
    for(;;)
    {
        l++; r--;
        if(r>l) cout<<l<<" "<<r<<'\n';
        else break;
    }
    l=m+(!(m&1));r=2*m+2;
    for(;;)
    {
        l++; r--;
        if(r>l) cout<<l<<" "<<r<<'\n';
        else break;
    }
    return 0;
}


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

int main(){
	// sengen
	int x[5];
	int ans;
	// nyuryoku
	for(int i=0;i<5;i++){
		cin >> x[i];
		if(x[i] != i+1){
			ans = i+1;
		}
	}
	// keisan
	cout << ans;
	// syutsuryoku
}

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


int main()
{
  	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	int l[Q], r[Q];
	int answer[N];
	int a, b;
	for (int i=0;i<Q;i++){
		cin >> l[i] >> r[i];
	}
	for (int i=0;i<N;i++){
		answer[i] = 0;
	}		
	for (int i=0;i<N-1;i++){
		answer[i+1] = answer [i];
		if(S.at(i)=='A' && S.at(i+1)=='C'){
			answer[i+1] += 1;
		}
	}
	for (int i=0;i<Q;i++){
		a = r[i]-1;
		b= l[i]-1;
		cout << answer[a] - answer[b] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  map<i64, i64> mp;
  rep(i,0,N) {
    i64 a;
    cin >> a;
    mp[a]++;
  }
  map<i64, i64> cnt;
  i64 sum = 0;
  i64 c = 0;
  for(auto p: mp) {
    cnt[p.second]++;
    sum += p.second;
  }
  vector<i64> ans(N + 1);
  auto chmax = make_chain(std::less<i64>());
  for(i64 i = N + 1; i --> 1;) {
    c += cnt[i];
    sum -= cnt[i] * i;
    chmax(ans[(sum + c * i) / i], i);
  }
  for(int i = N; i --> 0;) {
    chmax(ans[i], ans[i + 1]);
  }
  rep(i,1,N + 1) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 39168
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

// 全パターンのvectorを返す
vector<vector<int>> get_all_combinations(int n){
    vector<vector<int>> ret;
    for(int bit = 0; bit < (1 << n); ++bit){
        vector<int> S;
        for(int i = 0; i < n; ++i){
            if(bit & (1 << i)) {
                S.push_back(i + 1);
            }
        }
        ret.push_back(S);
    }
    return ret;
}

int main(){
    string S;
    cin >> S;
    int n = S.size() - 1;
    vector<vector<int>>  bit_all = get_all_combinations(n);
    ll ans = 0;
    //それぞれのパーテーションのセットに対して
    for(vector<int> bits : bit_all){
        vector<string> num_list;
        if(bits.size() == 0){
            ans += stoll(S);
            continue;
        }
        num_list.push_back(S.substr(0, bits[0]));
        for(int i = 0; i < bits.size() - 1; i++){
            num_list.push_back(S.substr(bits[i], bits[i + 1] - bits[i]));
        }
        num_list.push_back(S.substr(bits[bits.size()-1]));
        for(string num : num_list){
            ans += stoll(num);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
int dp[3001][3001];
void run(string s1, string s2, int n, int m){
  for(int i=0; i<=n; i++){
    for(int j=0; j<=m; j++){
      if(i==0 || j==0) dp[i][j] = 0;
      else if(s1[i-1] == s2[j-1]){
        dp[i][j] = 1+dp[i-1][j-1];
      }
      else{
        dp[i][j] = 0;
        dp[i][j] = max(dp[i][j], dp[i-1][j]);
        dp[i][j] = max(dp[i][j], dp[i][j-1]);
      }
    }
  }
}
int main()
{
    fast;
    string s1, s2;
    cin>>s1>>s2;
    int i = s1.size();
    int j = s2.size();
    run(s1, s2, i, j);
    vector<int> ans;
    while(i>0 && j>0){
      if(dp[i][j] == dp[i-1][j]) i--;
      else if(dp[i][j] == dp[i][j-1]) j--;
      else{
        ans.pb(i);
        i--;
        j--;
      }
    }
    reverse(ans.begin(), ans.end());
    for(int x: ans){
      cout<<s1[x-1];
    }
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 38800
j = list(map(int, input().split()))
counter = 0
n = j[0]
k = j[1]

for b in range(k+1, n+1):
  the = (b - k) * (n // b) + max(n % b + 1 - k, 0)
  if k ==0:
      the -= 1
  counter += the

print(counter)


Measured memory_bytes: 2940
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            if(A + B < 10)
            {
                WriteLine(A + B);
            }
            else
            {
                WriteLine("error");
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        if(s.size()%2==1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    char s[4],t[4];
    int cnt=0;
    scanf("%s",&s);
    scanf("%s",&t);

    for (int i = 0; i < 3; i++)
    {
        if (s[i]==t[i])
        {
            ++cnt;
        }
        
    }
    printf("%d\n",cnt);
    
    return 0;
}

Measured memory_bytes: 128
n, m = gets.chomp.split(' ').map(&:to_i)
if m == 0
  puts 0
  exit
end
cakes = []
n.times do
  cakes.push(gets.chomp.split(' ').map(&:to_i))
end
biases = [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]
max = 0
biases.each do |bias|
  values = cakes.map{|cake| cake[0] * bias[0] + cake[1] * bias[1] + cake[2] * bias[2]}.sort.reverse
  max_temp = values.slice(0..(m - 1)).inject(0, :+)
  max = max_temp if max < max_temp
end
puts max


Measured memory_bytes: 2168
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long A, long long B){
    if(A <10 && B<10){
        cout << A*B<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

vector<int> vec;

void solve(string ABCD){

    for(auto ch: ABCD){
        vec.emplace_back(ch - '0');
    }
    int A = vec[0];
    int B = vec[1];
    int C = vec[2];
    int D = vec[3];
    if(A + B + C + D == 7) cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
    else if(A + B + C - D ==7) cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
    else if(A + B - C + D == 7) cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    else if(A - B + C + D == 7) cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    else if(A - B - C + D == 7) cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    else if(A - B + C - D == 7) cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
    else if(A + B - C - D == 7) cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    else if(A - B - C - D == 7) cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
}

int main(){
    string ABCD;
    cin >> ABCD;
    solve(ABCD);
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lst=[[] for i in range(n)]
visited=[False for i in range(n)]
ans=[0]*n

for i in range(m):
      a,b=map(int,input().split())
      lst[a-1].append(b-1)
      lst[b-1].append(a-1)

Q=[0]
visited[0]=True

while Q:
  v=Q.pop(0)
  for i in lst[v]:
        if visited[i]==False:
              visited[i]=True
              ans[i]=v
              Q.append(i)

print('Yes')

for i in range(1,n):
      print(ans[i]+1)

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

#define ll long long
#define endl "\n"

const int mxn = 2e5;
int a[mxn];

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

    int n;
    cin>>n;

    map<int,int> mem;
    for (int i=0; i<n-1; ++i){
    	int x;
    	cin>>x;
    	mem[x]++;
    }
    for (int i=1; i<=n; ++i){
    	cout<<mem[i]<<endl;
    }

}

Measured memory_bytes: 13032
#include<stdio.h>
main(){
  int n,i,a=100000,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    a=a+a*0.05;
    c=a%1000;
    a=a/1000;
    if(c!=0){
      a++;
    }
    a=a*1000;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

struct unionFind {
	std::vector<ll> data;
	unionFind(ll x): data(x, -1) {};

	ll find(ll x){
		if(data[x]<0) return x;
		else return data[x] = find(data[x]);
	}

	ll unite(ll x, ll y){
		x = find(x);
		y = find(y);
		if(x==y) return 0;
		ll ret = data[x] * data[y];
		data[y] += data[x];
		data[x] = y;
		return ret;
	}

	ll size(ll x){
		return -data[find(x)];
	}
};

int main(){
	ll n, m;
	scanf("%ld %ld", &n, &m);
	std::vector<P> ab(m);
	REP(i, 0, m) scanf("%ld %ld", &ab[i].fi, &ab[i].se);
	
	unionFind tree(n);
	ll cnt = (n * n - n) / 2;
	std::vector<ll> ans(m);
	for(ll i=m-1; i>=0; i--){
		ans[i] = cnt;
		cnt -= tree.unite(ab[i].fi-1, ab[i].se-1);
	}

	REP(i, 0, m) printf("%ld\n", (ans[i]));
	return 0;
}



Measured memory_bytes: 4480
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int S(int n)
{
	int r = 0;
	while (n > 0)
	{
		r += n % 10;
		n /= 10;
	}

	return r;
}

int main()
{
	int N;
	cin >> N;
	int ans = N % S(N);
	if (ans == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static class Point {
		public int x;
		public int y;
		public int pre;
		public Point(){
			
		}
		public Point(int x1,int y1) {
			x = x1;
			y = y1;
		}
		public Point(int x1,int y1 ,int pre1) {
			x = x1;
			y = y1;
			pre= pre1;
		}
		public void setX(int x1){
			x =x1;
		}
	};
	
	final static int MAXN = 1000;
	private static Point S = new Point() ,G = new Point() ;   //表示起点和?点
	private static int N,W,H;
	private static char[][] graph = new char[MAXN][MAXN];   //存?
	private static int[][] vis = new int[MAXN][MAXN];   //存距?
	private static Point[] aim = new Point[10];  //存目?坐?
	
	private static int dx[] = {1,-1,0,0},dy[]={0,0,-1,1};
	
	public static void main(String[] args) {
		
		Scanner fin = new Scanner(System.in);		
		//?入数据
		H = fin.nextInt();
		W = fin.nextInt();
		N = fin.nextInt();
		fin.nextLine();
		for(int i=0; i<H; i++){
			String line = fin.nextLine().replace(" ", "");
			for(int j=0; j<W; j++){
				graph[i][j] = line.charAt(j);
				if(graph[i][j] == 'S'){
					S.x = i;
					S.y = j;
				}
				if(graph[i][j] >= '1' && graph[i][j] <= '9'){
					int t = graph[i][j] -'0';
					aim[t] = new Point(i,j);
				}
			}
		}
		int step = 0; 
		for(int i=1; i<=N; i++){
			G.x = aim[i].x;
			G.y = aim[i].y;
			step += bfs(S,G);
			S.x = G.x;
			S.y = G.y;
		}		
		System.out.printf("%d\n", step);

	}
	
	private static int bfs(Point S, Point G){
		Queue<Point> sq = new LinkedList<Point>();
		

		//?次遍?前，重置vis中存放的?
		for(int i=0 ;i<MAXN; i++){
			Arrays.fill(vis[i], -1);
		}
		
		sq.add(S);
		vis[S.x][S.y] = 0;
		while(!sq.isEmpty()){
			Point qh = sq.poll();		//返回?列中第一个元素，并?除一个元素						
			if(qh.x == G.x && qh.y == G.y){
				break;
			}
			for(int k =0; k<4; k++){
				//*****因??里??的是引用，所以一定要新?建qe，然后添加到?列中，其?才不会?
				Point qe = new Point(qh.x + dx[k], qh.y + dy[k]);
				
				if(check(qe.x,qe.y) == 1){					
					sq.add(qe);   //入?					
					vis[qe.x][qe.y] = vis[qh.x][qh.y] + 1;					
				}
			}
		}
		return vis[G.x][G.y];
	}
	private static int check(int x, int y){
		int flag=1;
		if(x<0 || x>=H || y<0 || y>=W)
			flag =0;
		else if(graph[x][y] == 'X' || vis[x][y] != -1)
	    	flag =0;		
		return flag;
	}

}

Measured memory_bytes: 155304
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string a,b;
            cin>>a>>b;
            b.pop_back();
            if(a==b)
            {
                cout<<"Yes"<<endl;
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
        return 0;
    }


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

int main(){
    string S;
    cin >> S;
    int N = S.length();
    int s0 = 0;
    int s1 = 0;
    for(int i  = 0; i < N ; ++i){
        if(i%2 == 0){
            if(S[i] == '1') s0 += 1;
        }
        else{
            if(S[i] == '0') s0 += 1;
        }
    }
    for(int i  = 0; i < N ; ++i){
        if(i%2 == 0){
            if(S[i] == '0') s1 += 1;
        }
        else{
            if(S[i] == '1') s1 += 1;
        }
    }
    if(s1 > s0) cout << s0 <<endl;
    else cout << s1 << endl;
}

Measured memory_bytes: 512
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <ctime>
#include <atcoder/lazysegtree>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
const int MOD = 998244353;
int power(int A, int B)
{
    A %= MOD;
    int res = 1;
    while (B & 1)
    {
        if (B & 1)
        {
            res = res * A % MOD;
        }
        A = A * A % MOD;
        B >>= 1;
    }
    return res;
}
class node
{
private:
    int v, len;

public:
    node()
    {
        v = 1;
        len = 1;
    }
    node(int V, int LEN)
    {
        v = V;
        len = LEN;
    }
    int getv()
    {
        return v;
    }
    int length()
    {
        return len;
    }
};
int n, q, G[200005], a, b, c;
node op(node A, node B)
{
    if (!B.length())
    {
        return A;
    }
    return node((A.getv() * (G[B.length()] - G[B.length() - 1] + MOD) % MOD + B.getv()) % MOD, A.length() + B.length());
}
node e()
{
    return node(0, 0);
}
node mapping(int A, node B)
{
    return A && B.length() ? node(A * G[B.length() - 1] % MOD, B.length()) : B;
}
int composition(int A, int B)
{
    return A ? A : B;
}
int id()
{
    return 0;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> q;
    G[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        G[i] = (G[i - 1] * 10 + 1) % MOD;
    }
    atcoder::lazy_segtree<node, op, e, int, mapping, composition, id> g(n);
    for (int i = 0; i < n; ++i)
    {
        g.set(i, node());
    }
    for (int i = 1; i <= q; ++i)
    {
        cin >> a >> b >> c;
        --a;
        g.apply(a, b, c);
        cout << g.all_prod().getv() << endl;
    }
    return 0;
}

Measured memory_bytes: 18244
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
ll m,k;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> m>>k;
    if(k>=pow(2,m)){
        return cout<<-1<<"\n",0;
    }
    if(m==0){
        if(k==0){
            return cout<<0<<" "<<0<<"\n",0;
        }
        return cout<<-1<<"\n",0;
    }
    if(m==1){
        if(k==0){
            return cout<<0<<" "<<0<<" "<<1<<" "<<1<<"\n",0;
        }
        return cout<<-1<<"\n",0;
    }
    cout<<k<<" ";
    for(int i=0;i<pow(2,m);i++){
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=pow(2,m)-1;i>=0;i--){
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<"\n";
    //1から2のn乗-1のxorは0 (2*kと2*k+1のxorは1->1が偶数個できる->0)
}  



Measured memory_bytes: 1792
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P,int>PP;
int a[1000006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int now = 0;
	rep(i, n) {
		if (a[i] == now + 1)now++;
	}
	if (now)cout << n - now << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 1792
// AOJ 1305: Membership Management
// 2017.10.3 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define HASHSIZ 2003
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;  // Hash table

char name[1002][16]; int sz;
int info[1002];
char got[1002];

typedef struct { int id, lock, n, m[11]; } T;
T group[102]; int n;

int lookup(char *s, int id)
{
	int w = strlen(s);
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp;

	tp = hash + i;
	while (tp->s != NULL) {
		if (!memcmp(tp->s, s, w)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

int count(int m)
{
	int i, id, s;

	if (group[m].lock) return 0;
	group[m].lock = 1;
	for (s = 0, i = 0; i < group[m].n; i++) {
		id = group[m].m[i];
		if (info[id] >= 0) s += count(info[id]);
		else if (!got[id]) got[id] = 1, s++;
	}
	return s;
}

int main()
{
	int i, j, id;
	char buf[200], *p, *q;

	while (scanf("%d", &n) && n > 0) {
		sz = 0; memset(hash, 0, sizeof(hash));
		for (i = 0; i < n; i++) {
			scanf("%s", buf);
			p = buf; while (isalpha(*p)) p++;
//			if (*p != ':') while (1); // panic
			*p++ = 0;
			strcpy(name[sz], buf);
			if ((id = lookup(name[sz], sz)) < 0) id = sz++;
			group[i].id = id;  // group
			j = 0; while (*p) {
				q = p; while (isalpha(*p)) p++;
				*p++ = 0;
				strcpy(name[sz], q);
				if ((id = lookup(name[sz], sz)) < 0) id = sz++;
				group[i].m[j++] = id;
			}
			group[i].n = j, group[i].lock = 0;
		}
		memset(info, -1, sizeof(int)*sz);
		for (i = 0; i < n; i++) info[group[i].id] = i;
		memset(got, 0, sizeof(char)*sz);
		printf("%d\n", count(0));
	}
	return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1001000
#define llg long long 
#define md 1000000007
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,x[maxn],y[maxn],VALY,ans,val;

inline int getint()
{
       int w=0,q=0; char c=getchar();
       while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
       while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
}


int main()
{
	//yyj("B");
	cin>>n>>m;
	for (llg i=1;i<=n;i++) x[i]=getint();
	for (llg i=1;i<=m;i++) y[i]=getint();
	sort(y+1,y+m+1);
	VALY=0;
	for (llg i=1;i<=m;i++)
	{
		VALY+=(i-1)*y[i]-val; VALY%=md;
		val+=y[i];
	}
	sort(x+1,x+n+1);
	val=0;
	for (llg i=1;i<=n;i++)
	{
		ans+=VALY*(((i-1)*x[i]-val)%md); ans%=md;
		val+=x[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(v) v.begin(), v.end()

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  vector<pair<int, int>> ab(M);
  rep (i, M) {
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  vector<int> path(N);
  rep(i, N) path[i] = i + 1;
  int result = 0;
  do {
    if (path.end() == adjacent_find(all(path), [&](int l, int r) {
      return none_of(all(ab), [&](auto p) {
        return ((p.first  == l) && (p.second == r)) ||
               ((p.second == l) && (p.first  == r));
        });
      })) {
      ++result;
    }
  } while (next_permutation(path.begin() + 1, path.end()));
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    int ans = -1;

    rep(i,1010){
        if(int(i*0.08) == a && int(i*0.1) == b){
            ans = i;
            break;
        }
    }

    dunk(ans);
}

Measured memory_bytes: 256
N,L = list(map(int,input().split()))
sum = 0
list1 = []
list2 = []
for i in range(N):
    sum = sum+i+L

    list1.append(abs(i+L))
    list2.append(i+L)
print(sum - list2[list1.index(min(list1))])


Measured memory_bytes: 2940