akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1000000007;
int main()
{
    ll n , m ;
    cin >> n >> m ;
    char arr[n][m];
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin >> arr[i][j];
        }
    }
    if(arr[0][0]=='#'||arr[n-1][m-1]=='#'){
        cout << 0 << endl;
        return 0 ;
    }
    ll dp[n][m];
    memset(dp,0,sizeof dp);
    for(ll i=1;i<n;i++){
        if(arr[i][0]=='#') break;
        dp[i][0]=1;
    }
    for(ll j=1;j<m;j++){
        if(arr[0][j]=='#') break;
        dp[0][j]=1;
    }
    for(ll i=1;i<n;i++){
        for(ll j=1;j<m;j++){
            if(arr[i][j]=='#') continue;
            dp[i][j]=dp[i-1][j]%MOD+dp[i][j-1]%MOD;
            dp[i][j]%=MOD;
        }
    }
   /* for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cout << dp[i][j] << " " ;
        }
        cout << endl;
    }*/
   cout << dp[n-1][m-1] << endl;
    return 0;
}


Measured memory_bytes: 9088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int m = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if (n == 0 && m == 0)
				break;
			
			//
			m++;
			int[] wish = new int[m];

			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				for (int j = 1; j < m; j++) {
					if (st.nextToken().equals("1"))
						wish[j]++;
				}
			}
			StringBuilder sb = new StringBuilder();
			for (int i = n; i >= 0; i--) {
				for (int j = 1; j < m; j++) {
					if (wish[j] == i)
						sb.append(j + " ");
				}
			}
			System.out.println(sb.toString().substring(0, sb.length() - 1));
		}
	}
}

Measured memory_bytes: 31084
N, K = [int(n) for n in input().split()]

A = [int(n) for n in input().split()]

count = 0
for i in range(1,N+1):
    A[i-1] = A[i-1]-1

check = {0: [0,1,[0]]}

s = 0
for i in range(1,N+1):
    s = (s + A[i-1]) % K
    if s in check:
        j = check[s][0]
        l = check[s][1]
        while j < l and i - check[s][2][j] >= K:
            j += 1
        check[s][0] = j
        count += l - j
        check[s][2].append(i)
        check[s][1] = l + 1
    else:
        check[s] = [0,1,[i]]

print(count)

Measured memory_bytes: 73764
a,b = map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

ld=divisor(gcd(a,b))
ld.sort()
#ld.append(1)

#ld2 = divisor(gcd(a,b))
cnt=0
#print(ld)
ansl=[]
for i in ld:
    flg=0
    for j in ansl:
        #if i==j or i==1:
        #    break
        if gcd(i,j) !=1:
            flg = 1
            #print('flg',i,j)
            #if j in ld:
            #    print('in',i,j,gcd(i,j))
            #    ld.remove(j)
            break
        #print(i,j,gcd(i,j))
    if flg == 0:
        ansl.append(i)
    #print(ansl)


print(len(ansl))

#print(ld)

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    long long a,b,k;
    cin>>a>>b>>k;
    
    if(a>=k){
        cout<<a-k<<" "<<b<<endl;
    }else if(a+b>=k){
        cout<<0<<" "<<a+b-k<<endl;
    }else{
        cout<<0<<" "<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;

    rep(i, n) {
        for (int j = i; j < n; j++) {
            bool ok = true;
            rep(k, n-j) {
                if (s[j+k] != t[k]) ok = false;
            }
            if (ok) {
                cout << n+j << endl;
                return 0;
            }
        }
    }
    cout << 2*n << endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <array>

using namespace std;

static void inputArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    cin >> A[i]; 
  }
}

static int linearSearch(int A[], int sentinel) {
  int i = 0;
  for (; A[i] != sentinel; i++);
  return i;
}

int main() {
  array<int, 10000 + 1> N;
  array<int, 500> Q;
  int s, t;

  cin >> s;
  inputArray(&N[0], s);

  cin >> t;
  inputArray(&Q[0], t);

  int found = 0;
  for (int i = 0; i < t; i++) {
    // set a sentinel
    N[s] = Q[i];
    if (linearSearch(&N[0], Q[i]) != s) {
      found++; 
    }
  }
  cout << found << endl;  

  return 0;
}



Measured memory_bytes: 3144
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] t = new int[N+1];
        int[] x = new int[N+1];
        int[] y = new int[N+1];
        int[] dist = new int[N];
        int[] t_diff = new int[N];
        t[0] = 0; x[0] = 0; y[0] = 0;
        for(int i = 1; i < N+1; i++){
            t[i] = in.nextInt();
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
        String ret = "Yes";
        for(int i = 0; i < N; i++){
            dist[i] = Math.abs(x[i] - x[i+1]) + Math.abs(y[i] - y[i+1]);
            t_diff[i] = t[i+1] - t[i];
            if(dist[i] > t_diff[i] || (t_diff[i] - dist[i])%2==1 ){
                ret = "No";
                break;    
            }
        }
        System.out.println(ret);
        in.close();
    }
}


Measured memory_bytes: 92928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll inf=1e15;
    vector<ll> dp(n, inf);
    rep(i,n){
        auto itr=lower_bound(dp.begin(), dp.end(), a[i]);
        ll index=itr-dp.begin();
        dp[index]=a[i];
    }
    ll res=0;
    rep(i,n){
        if(dp[i]<inf){
            res=i;
        }
    }
    cout<<res+1<<endl;
    return 0;
}


Measured memory_bytes: 4384
use proconio::{input, marker::Chars};
use std::collections::HashSet;

fn main() {
    input! {
        s: Chars,
    }

    let mut chars = HashSet::new();

    for &c in s.iter() {
        chars.insert(c);
    }

    let mut min = None;

    for c in chars {
        let mut s = s.clone();
        let mut count = 0;
        while s.iter().any(|&e| e != c) {
            for i in 0..s.len()-1 {
                if s[i] == c || s[i+1] == c {
                    s[i] = c;
                }
            }
            s.pop();
            count += 1;
        }
        if let Some(min) = min.as_mut() {
            *min = std::cmp::min(count, *min);
        } else {
            min = Some(count);
        }
    }

    if let Some(min) = min {
        println!("{}", min);
    } else {
        unreachable!();
    }
}


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

int compare_int(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(void){
  int n;
  scanf("%d\n", &n);
  int a[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  qsort(a, n, sizeof(int), compare_int);
  a[n-1] /= 2;
  int sum = 0;
  for(int i = 0; i<n; i++){
    sum += a[i];
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int l, a[200005];
int dp[200005][5];
signed main() {
	cin >> l;
	rep(i, l)cin >> a[i];
	rep(i, l + 1)rep(j, 5)dp[i][j] = inf;
	dp[0][0] = 0;
	rep(i, l) {
		rep(j, 5) {
			if (!j)chmin(dp[i + 1][0], dp[i][j] + a[i]);
			if (j <= 1)chmin(dp[i + 1][1], dp[i][j] + (a[i] ? a[i] % 2 : 2));
			if (j <= 2)chmin(dp[i + 1][2], dp[i][j] + ((a[i] % 2) ^ 1));
			if (j <= 3)chmin(dp[i + 1][3], dp[i][j] + (a[i] ? a[i] % 2 : 2));
			chmin(dp[i + 1][4], dp[i][j] + a[i]);
		}
	}
	int ans = inf;
	rep(i, 5)chmin(ans, dp[l][i]);
	cout << ans << endl;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w,h,n,a,b,c,xcnt=0,ycnt=0;
	cin>>w>>h>>n;
	vector<bool>x(w),y(h);
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		if(c==1){
			for(int j=0;j<a;j++){
				x.at(j)=true;
			}
		}else if(c==2){
			for(int j=a;j<w;j++){
				x.at(j)=true;
			}
		}else if(c==3){
			for(int j=0;j<b;j++){
				y.at(j)=true;
			}
		}else if(c==4){
			for(int j=b;j<h;j++){
				y.at(j)=true;
			}
		}
	}
	for(int i=0;i<w;i++){
		if(x.at(i)==0){
			xcnt++;
		}
	}
	for(int i=0;i<h;i++){
		if(y.at(i)==0){
			ycnt++;
		}
	}
	cout<<xcnt*ycnt<<endl;
}


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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  string S;
  int Q;
  cin >> S >> Q;

  int front=1;
  int T;
  int F;
  string C;
  for(int i=0;i<Q;i++){
    cin >> T;
    if(T==1)  front^=1;
    else{
      cin >> F >> C;
      if(front==1){
        if(F==1)  S.insert(0,C);
        else  S+=C;
      }
      else if(front==0){
        if(F==1)  S+=C;
        else  S.insert(0,C);
      }
    }
  }
  if(front==1)  cout << S << endl;
  else{
    reverse(S.begin(),S.end());
    cout << S << endl;
  }

  return 0;
}


Measured memory_bytes: 912
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int[]counta=new int[n];
		int count=0;
		int []block=new int[n];
		for(int i=0;i<n;i++){
			block[i]=scan.nextInt();
			if(0<i){
				if(block[i]<=block[i-1]){
					count++;
				}else{
					counta[i]=count;
					count=0;
				}
			}
			if(i==n-1){
				counta[i]=count;
			}
		}
		Arrays.sort(counta);
		System.out.println(counta[n-1]);
	}
}


Measured memory_bytes: 49756
l,r = map(int,input().split())
a = float("inf")
for i in range(l,min(r+1,l+2019)):
               for j in range(i+1,min(r+1,l+2019)):
                              if a > (i*j)%2019:
                                 a = (i*j)%2019
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n, d;
  cin >> n >> d;

  vector<vector<int > > X(n, vector<int >(d, 0));
  REP(i, n){
    REP(j, d){
      cin >> X[i][j];
    }
  }
  int count = 0;
  double sumd = 0;
  int sumi = 0;
  REP(i, n){
    for(int j = i + 1; j < n; j ++){
      sumd = 0.0;
      sumi = 0;
      REP(k, d){
	sumd += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
      }
      sumi = (int)sqrt(sumd);
      if(sumi*sumi == sumd){
	count ++;
      }
    }
  }
  cout  << count << endl;
  
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll c[30],s[370][30];
int a[370],last[30];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);

ll f(int d)
{
    ll x=0;
    memset(last,-1,sizeof(last));
    for(int i=0;i<d;i++){
        x+=s[i][a[i]];
        last[a[i]]=i;
        for(int j=0;j<26;j++){
            x+=c[a[i]]*(i-last[a[i]]);
        }
    }
    return x;
}

int main()
{
    auto start=chrono::high_resolution_clock::now();
    ll x=0,sc=0;
    int d,ans[370];
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
        sc+=c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    if(sc==0){
        for(int i=0;i<d;i++){
            int mx=-1,j=-1;
            for(int k=0;k<26;k++){
                if(s[i][k]>mx) mx=s[i][k],j=k;
            }
            printf("%d\n",j+1);
        }
        return 0;
    }
    while(true){
        for(int i=0;i<d;i++) a[i]=rng()%26;
        ll y=f(d);
        if(y>x) copy(a,a+d,ans),x=y;
        auto stop=chrono::high_resolution_clock::now();
        int duration=chrono::duration_cast<chrono::microseconds>(stop-start).count();
        if(2000000-duration<100000) break;
    }
    for(int i=0;i<d;i++){
        printf("%d\n",a[i]+1);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3908
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		(new Solver()).Solve();
	}
}


public class Solver
{
	private int N;
	private List<int>[] adj = null;
	
	public Solver()
	{
		N = GetInt();
		adj = new List<int>[N+1];
		for(int i = 1; i <= N; i++)
			adj[i] = new List<int>();
		for(int i = 0; i < N-1; i++)
		{
			int a = GetInt();
			int b = GetInt();
			adj[a].Add(b);
			adj[b].Add(a);
		}
	}

	public void Solve()
	{
		int[] db = new int[N+1];
		int[] dw = new int[N+1];
		for(int i = 1; i <= N; i++)
		{
			db[i] = -1;
			dw[i] = -1;
		}
		db[1] = 0;
		dfs(db, 1);

		dw[N] = 0;
		dfs(dw, N);
		
		int numBlack = 0;
		for(int i = 1; i <= N; i++)
			if(db[i] <= dw[i])
				numBlack++;
		int numWhite = N - numBlack;
		Console.WriteLine((numBlack > numWhite) ? "Fennec" : "Snuke");		
	}

	private void dfs(int[] d, int v)
	{
		foreach(int u in adj[v])
		{
			if(d[u] != -1)
				continue;
			d[u] = d[v] + 1;
			dfs(d, u);
		}
	}
}



public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 40076
#include <iostream>
#define ll long long
using namespace std;

ll n, nn,d=1;
int ans;

int main() {
	cin >> n;
	nn = n;
	while (nn / 10) {
		nn /= 10;
		ans += 9;
		d *= 10;
	}
	
	if ((nn + 1)*d - 1 == n) ans += nn;
	else ans += (nn - 1);
	
	cout << ans;
	system("pause");
	return(0);
}

Measured memory_bytes: 504
#include<iostream>
using namespace std;
int count(int n,int x){
     int cnt=0;
    for(int i=1;i<=n-2;i++){
        for(int j=i+1;j<=n-1;j++){
            for(int k=j+1;k<=n;k++){
                if(i+j+k==x)cnt++;
            }
        }
    }
    return cnt;
}
int main(){
    int n,x;
    while(1){
    cin>>n>>x;
    if(n==0&&x==0)break;
    cout<<count(n,x)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;

int main() {
  int n;
  string a;
  cin >> n >> a;
  int cnt[30] = {};
  for (int i = 0; i < n; i++) {
    cnt[a[i] - 'a']++;
  }
  int ans = 1;
  for (int i = 0; i < 30; i++) {
    ans = (1ll * ans * (cnt[i] + 1)) % mod;
  }
  ans = (ans - 1 + mod) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.awt.Checkbox;
import java.lang.invoke.ConstantCallSite;
import java.security.spec.ECPrivateKeySpec;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	static int a[], b[];
	static int N, K, Q;
	public static boolean check(int low, int high) {
		int last = -1;
		int total = 0;
		int cnt = 0;
		for (int i = 0; i <= N; i++) {
			if (i == N || a[i] < low) {
				///last + 1 -> i - 1 is okay
				total += Math.min(cnt, Math.max(0, (i - 1 - (last + 1) + 1) - K + 1));
				last = i;
				cnt = 0;
			} else 
			if (a[i] >= low && a[i] <= high) cnt++;
		}
		if (total >= Q) return true; else 
		return false;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		N = in.nextInt(); K = in.nextInt(); Q = in.nextInt();
		a = new int[N];
		for (int i = 0; i < N; i++) a[i] = in.nextInt();
		
		b = new int[N];
		for (int i = 0; i < N; i++) b[i] = a[i];
		Arrays.sort(b);
		//for (int i = 0; i < N; i++) System.out.print(b[i] + " "); System.out.println("");
		//System.out.println(check(1, 2));
		
		int result = (int)1e9;
		
		for (int i = 0; i < N; i++) {
			int low = i, high = N - 1, res = N;
			while (low <= high) {
				int mid = (low + high) >> 1;
				if (check(b[i], b[mid])) {
					res = mid;
					high = mid - 1;
				} else low = mid + 1;
			}
			if (res >= i && res < N) {
				result = Math.min(result, b[res] - b[i]);
			}
		}
		
		System.out.println(result);
	}
}

Measured memory_bytes: 28144
input()
H = list(map(int, input().split()))
count = 0
while any([h != 0 for h in H]):
    n = 0
    prev = 0
    for h in H:
        if prev == 0 and h != 0:
            n += 1
        prev = h
    count += n
    H = list(map(lambda x: x if x == 0 else x - 1, H))
print(count)


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 800;

int K;
int ans[N + 5][N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(K);
    if(K == 1) return puts("1\n1"), 0;

    for(int n = 2; ; n += 2) if(2 * n >= K) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                ans[i][j] = (i + j) % n + (i & 1) * n;
            }
        }
            
        int del = 2 * n - K;

        printf("%d\n", n);
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                int c = (ans[i][j] >= 2 * n - del) ? ans[i][j] - n : ans[i][j];
                printf("%d ", c + 1);
            }
            puts("");
        }
        break;
    }

    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
		return a<x.a;
	}
};
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const ll p=1000000007ll,inf=1000000000000000000ll;
const int N=200005;

int main(){
	string a,b;
	cin>>a>>b;
	printf("%d",(a[0]==b[0])+(a[1]==b[1])+(a[2]==b[2]));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,p;
    cin>>a>>p;
    int ans;
    ans=3*a+p;
    ans/=2;
    cout<<ans<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    int x[100];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int j = n - 1; j >= 1;j--)
        cout << x[j]<<" ";
    cout << x[0]<<endl;
    return 0;
}

Measured memory_bytes: 1160
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
};
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n = inp();
    vector<ll> a = inp(n);
    
    vector<ll> al(n+1, 0), ar(n+1, 0);
    REP(i, n) {
        al[i+1] = al[i] + abs(a[i] - (!i ? 0 : a[i-1]));
        ar[i+1] = ar[i] + abs(a[n-i-1] - (!i ? 0 : a[n-i]));
    }
    REP(i, n) {
        ll x1 = i == 0 ? 0 : a[i-1];
        ll x2 = i == n-1 ? 0 : a[i+1];
        cout << al[i] + ar[n-i-1] + abs(x1 - x2) << endl;
    }
    
}

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

using namespace std;

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

  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
        ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << ans;

  return 0;
}

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

int check[301];
int list[4][1000];
void init()
{
	for(int i=0;i<301;i++){
		check[i] = 2;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<1000;j++){
			list[i][j] = 0;
		}
	}
}
int main()
{
	int a,b,c,n;
	while(cin >> a >> b >> c){
		if(a==0&&b==0&&c==0)
			break;
		cin >> n;
		init();
		for(int i=0;i<n;i++){
			cin >> list[0][i] >> list[1][i] >> list[2][i] >> list[3][i];
			if(list[3][i] == 1){
				check[list[0][i]]=1;check[list[1][i]]=1;check[list[2][i]]=1;
			}
		}
		for(int i=0;i<n;i++){
			if(list[3][i]==0){
				if(check[list[0][i]]==1&&check[list[1][i]]==1)
					check[list[2][i]] = 0;
				if(check[list[1][i]]==1&&check[list[2][i]]==1)
					check[list[0][i]] = 0;
				if(check[list[2][i]]==1&&check[list[0][i]]==1)
					check[list[1][i]] = 0;
			}
		}
		for(int i=1;i<=a+b+c;i++){
			cout << check[i] << endl;
		}
	}
	return 0;
}

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

int main() {  
  int N;
  cin >> N;
  int ans=0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    int a=A.at(i);
    while(a%2==0){
      ans++;
      a/=2;
    }
  }  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))
At_list = [A_list[0]]
D_list = list()
Dt_list = list()
mone = 1000
stoc = 0
for i in range(1,len(A_list)):
    D_list.append(A_list[i]-A_list[i-1])
for h in range(len(D_list)):
    if D_list[h] != 0:
        Dt_list.append(D_list[h])
        At_list.append(A_list[h + 1])
for j in range(len(Dt_list)):
    if Dt_list[j] > 0:#買う
        stoc = stoc + mone // At_list[j]
        mone = mone % At_list[j]
    elif Dt_list[j] < 0:
        mone = mone + stoc * At_list[j]
        stoc = 0
        last_sell = j
if len(Dt_list) != 0:
    if At_list[-1] >= At_list[-2]:
        mone = mone + stoc * At_list[-1]
    else:
        mone = mone + stoc * At_list[last_sell]
else:
    mone = 1000
print(mone)

Measured memory_bytes: 62016
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=200010;
vi v;
int a[N];
int main()
{
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[i]=x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	x=n/2-1;
	int y=n/2;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=v[x])
		cout<<v[y]<<"\n";
	else
		cout<<v[x]<<"\n";
	}

	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a[3],k;
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
  }
  cin>>k;
  int j=0;
  //int cards
  
  long long int cards=0;
  
  while(k)
  {
    if(k-a[j]>0)
    {
      if(j==0)
        cards+=a[j] ;
      if(j==2)
         cards-=a[j];
        
      k-=a[j];  
      
      j++;
    }
      
      else
      {
        if(j==0)
          cards+=k;
        if(j==2)
          cards-=k;
          
        k=0;
      }
        
  }
  
  cout<<cards;
  
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
using namespace std;

const int mod = 1000000007;
signed main(void)
{
	int n;
	long long ans;
	string s1, s2, t;

	cin >> n >> s1 >> s2;
	rep(i, n)
	{
		if (s1[i] == s2[i])
			t += 'X'; 
		else
		{
			t += 'Y';
			i++;
		}
	}
	ans = 0;
	rep(i, t.size())
	{
		if (i == 0)
		{
			if (t[i] == 'X')
				ans = 1;
			else
				ans = 2;
		}
		else
		{
			if (t[i] == 'X')
			{
				if (t[i - 1] == 'X')
					ans *= 2;
				else if (t[i - 1] == 'Y')
					ans *= 1;
			}
			else if (t[i] == 'Y')
			{
				if (t[i - 1] == 'X')
					ans *= 2;
				else if (t[i - 1] == 'Y')
					ans *= 3;
			}
		}
		ans %= mod;
	}
	ans *= 3; 
	cout << ans % mod << endl;
	return 0;
}


Measured memory_bytes: 256
import math

a,b = map(int,input().split())

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))+1):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return list(set(ret))

def trial_division(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    for i in range(3, int(math.ceil(math.sqrt(n))) + 1, 2):
        if n % i == 0:
            return False
    return True

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

count = 1
for ci in c:
  if trial_division(ci):
    count+=1

print(count)

Measured memory_bytes: 4748
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 10**18
    tmp = abs(ans  - n)
    p = set(p)
    for i in range(-1000, 1001):
        if i in p:
            continue
        buf = abs(i - x)
        if buf < tmp:
            ans = i
            tmp = buf
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    ll n;
    cin >> n;
    int r=0;
    string s;
    cin >> s;
    rep(i,n) {
        if(s[i]=='R') r++;
    }
    int cnt=0;
    rep(i,r) {
        if(s[i]=='R') cnt++; 
    }
    cout << r-cnt << endl;
}

Measured memory_bytes: 3428
#include <fstream>
#include <algorithm>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, K;
int fact [100000];
int arr [100000];
int psum [100001]; // psum[i+1] = sum up to i

int modexp(int a, int e) {
    int ans = 1;
    int cur = a;
    while (e) {
        if (e&1) {ans = mul(ans, cur); e--;}
        e /= 2;
        cur = mul(cur,cur);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> K;
    F0R(i,N) cin >> arr[i];
    if (K == 1) {cout << "0\n"; return 0;}
    sort(arr, arr+N);
    fact[0] = 1;
    FOR(i,1,N) fact[i] = mul(fact[i-1], i);
    psum[0] = 0;
    FOR(i,1,N+1) psum[i] = add(psum[i-1], arr[i-1]);

    int ans = 0;
    F0R(i,N) { // diff vals
        if (i < K-1) continue;
        int psm = (MOD+add(add(psum[N], -psum[i]), add(-psum[N-i], psum[0])))%MOD;
        ans = add(ans, 
        mul(mul(fact[i-1], modexp(mul(fact[K-2], fact[i+1-K]),MOD-2)),psm));
    }
    cout << ans << '\n';
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long

#define for(i,a,b) for (i=a; i<b; i++)
#define forb(i,a,b) for (i=a; i>b; i--)
#define all(S) S.begin(),S.end()
#define sort(S) sort(all(S))

const int inf = 1e9;
const ll INF = 1e18;

int dp[2019];

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    ll i,j,n,m=0;
    cin >> s;
    n=s.size();
    for (i,0,2019)
        dp[i]=0;
    dp[s[0]-'0']++;
    dp[0]++;
    for(i,1,n)
    {
        int q = s[i]-'0';
        bool b = false;
        vector <int> V(2019);
        for (j,0,2019)
        {
            V[(j*10+q)%2019]=dp[j];
            if ((j*10+q)%2019==0)
            {
                b=true;
                m+=dp[j];
                V[(j*10+q)%2019]++;
            }
        }
        if (!b)
            dp[0]++;
        for (j,0,2019)
            dp[j]=V[j];
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 3808
n = int(input())
a = list(map(int, input().split()))
a.insert(0, -1)
a.append(-1)
m = []
cnt = 0
for i in range(1, len(a)):
    if a[i] != a[i-1]:
        if cnt != 0:
            m.append(cnt)
        cnt = 1
    else:
        cnt += 1
total = 0
for i in m:
    total += i // 2
print(total)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fst first
#define snd second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1e9+10;
const int MOD = 1000000007;

ll A[200005];
ll B[200005];

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

  int N,M,K;
  cin >> N >> M >> K;
  for(int i=1;i<=N;i++){
    cin >> A[i];
    A[i] += A[i-1];
  }
  for(int i=1;i<=M;i++){
    cin >> B[i];
    B[i] += B[i-1];
  }
  int ans = 0;
  int j = M;
  for(int i=0;i<=N;i++){
    if(A[i] > K) break;
    while(B[j] > K - A[i]) j--;
    ans = max(ans, i+j);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 6752
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

#define rep(i, n) for (long long i = 0; i < n; i++)

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

const ll MOD = 1000000007;

void solve() {
    inl(N);

    ll ret = 1;
    rep(i, N)
        ret = (ret * (i + 1)) % MOD;
    out(ret);
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 1e3 + 7;
int x, y, z, k;
LL a[maxx], b[maxx], c[maxx];
vector <LL> vec;
priority_queue <LL> qua;
LL tmp[3 * maxx];

void Init() {
	scanf("%d %d %d %d", &x, &y, &z, &k);
	for(int i = 1; i <= x; i++) scanf("%lld", &a[i]);
	for(int i = 1; i <= y; i++) scanf("%lld", &b[i]);
	for(int i = 1; i <= z; i++) scanf("%lld", &c[i]);
}

int main() {
	Init();
	for(int i = 1; i <= x; i++) {
		for(int j = 1; j <= y; j++) {
			LL num = a[i] + b[j];
			qua.push(num);
		}
	}
	int cnt = 0;
	while(!qua.empty()) {
		if(cnt < k) tmp[++cnt] = qua.top();
		qua.pop();
	}
	for(int i = 1; i <= k; i++) {
		for(int j = 1; j <= z; j++) {
			LL num = tmp[i] + c[j];
			qua.push(num);
		}
	}
	int tot = 0;
	while(!qua.empty()) {
		tot++;
		printf("%lld\n", qua.top());
		qua.pop();
		if(tot == k) break;
	}
	return 0;
}

Measured memory_bytes: 35172
import java.util.Scanner;

/**
 * A
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();

        System.out.println((a + b) * h / 2);
        sc.close();
    }
}

Measured memory_bytes: 22224
price_A, price_B, price_AB, num_A, num_B = map(int,input().split())
AandB = price_A * num_A + price_B * num_B
if num_A >= num_B:
    minAB = price_AB*num_B*2 + price_A*(num_A-num_B)
else:
    minAB = price_AB*num_A*2 + price_B*(num_B-num_A)
maxAB = price_AB * max(num_A, num_B) * 2
print(min(AandB, minAB, maxAB))

Measured memory_bytes: 9060
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val n, k = sc.nextInt
  val s = sc.next
  val sizes = {
    var ss = s.split("((?!1)(?<=1)|(?!0)(?<=0))").map(_.size)
    if (s.head == '0') ss = 0 +: ss
    if (s.last == '0') ss = ss :+ 0
    ss
  }

  def search(max: Int, pre: Int, i: Int): Int = {
    if (i + k * 2 > sizes.size) max
    else {
      val cur = pre - sizes(i - 2) - sizes(i - 1) + sizes(i + k * 2 - 1) + sizes(i + k * 2)
      search(Math.max(max, cur), cur, i + 2)
    }
  }
  val first = sizes.take(k * 2 + 1).sum
  println(search(first, first, 2))
}

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

int main(int argc, char const *argv[])
{
  while(1)
  {
    int H, W;
    cin >> H >> W;
    if(H == 0 && W == 0) break;

    for(int i = 0; i < H; i++)
    {
      for(int j = 0; j < W; j++)
      {
        cout << ((i+j)%2 == 0 ? "#" : ".") << flush;
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
def main():
    import sys
    input = sys.stdin.readline
    N, M, X = map(int, input().split())
    books = [list(map(int, input().split())) for _ in range(N)]
    ans = float("inf")
    for i in range(2**N):
        cost = 0
        score = [0] * M
        for j in range(N):
            if ((i >> j) & 1):
                cost += books[j][0]
                for k in range(1, M+1):
                    score[k-1] += books[j][k]
        flag = True
        for j in range(M):
            if score[j] < X:
                flag = False
                break
        if flag:
            ans = min(ans, cost)
    if ans == float("inf"):
        print("-1")
    else:
        print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 68700
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n], b[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i= 0; i < n; i++)
        cin >> b[i];
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[i] > b[i])
            sum += a[i] - b[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, L = map(int, input().split())

        pie = [L + i - 1 for i in range(1, N + 1)]
        print(sum(pie) - min(pie, key=abs))

# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38384
local n = io.read('*n')
local x = io.read("*n")
io.read("*l")
local a = {}
for i = 1, n do
	a[i] = io.read("*n")
end
local b = {}
for i = 1, n do
	b[i] = {}
	b[i][0] = a[i]
	for j = 1, n - 1 do
		local idx = i - j
		if idx <= 0 then
			idx = idx + n
		end
		b[i][j] = math.min(a[idx], b[i][j - 1])
	end
end

local min = math.huge
local sum
for j = 0, n - 1 do
	sum = 0
	for i = 1, n do
		sum = sum + b[i][j]
	end
	sum = sum + j * x
	min = math.min(sum, min)
end
print(min)

Measured memory_bytes: 67072
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll r;
    cin >> r;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int H,W,h,w;
int data[555];

void solve(int x,int y)
{
	int i,j;

	for(i = 0;i < x;++i)
		if((i % y) >= (x % y))
			data[i] = -1000;
		else if((i % y) == 0)
			data[i] = 1000 * (y - (x % y));
		else
			data[i] = 0;
	for(i = 0;i < x;++i)
		--data[i];
}

int main(void)
{
	int i,j;

	//freopen("x.in","r",stdin);

	scanf("%d %d %d %d",&H,&W,&h,&w);

	if(!(H % h) && !(W % w))
		return puts("No"),0;

	puts("Yes");
	if(H % h){
		solve(H,h);
		for(i = 0;i < H;++i)
			for(j = 0;j < W;++j)
				printf("%d%c",data[i]," \n"[j == W - 1]);
	}else{
		solve(W,w);
		for(i = 0;i < H;++i)
			for(j = 0;j < W;++j)
				printf("%d%c",data[j]," \n"[j == W - 1]);
	}

	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, q;
  string s;
  cin >> n >> s >> q;
  
  vector<set<int>> x(26); // 0-indexed
  for (int i = 0; i < n; i++) x.at(s.at(i) - 'a').insert(i);
  
  for (int i = 0; i < q; i++) {
    int num;
    cin >> num;
    if (num == 1) {
      int j;
      char c;
      cin >> j >> c;
      j--;
      x.at(s.at(j) - 'a').erase(j);
      x.at(c - 'a').insert(j);
      s.at(j) = c;
    }
    else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      int count = 0;
      for (int j = 0; j < 26; j++) {
        auto check1 = x.at(j).upper_bound(r);
        auto check2 = x.at(j).lower_bound(l);
        if (distance(check1, check2) > 0) count++;
      }
      cout << count << '\n';
    }
  }
}

Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll x,y;
    cin >> x >> y;
    ll res = 0;
    if(x==3) res += 100000;
    if(x==2) res += 200000;
    if(x==1) res += 300000;
    if(y==3) res += 100000;
    if(y==2) res += 200000;
    if(y==1) res += 300000;
    if(x==1 && y==1) res += 400000;
    cout << res << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstring>
int map[99][99];
int xi[]={-1,-1,-1,0,0,1,1,1};
int yi[]={-1,0,1,-1,1,-1,0,1};

using namespace std;

void map_clear(int x,int y)
{
  map[x][y]=0;
  for(int i=0;i<8;i++)
    {
      if(x+xi>=0 && y+yi>=0 && map[x+xi[i]][y+yi[i]] == 1)
	map_clear(x+xi[i],y+yi[i]);
    }
}

int main()
{
  int w,h;
  for(;cin>>w>>h,w;)  
    {
      memset(map,0,sizeof(map));
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  cin>>map[i][j];
      int c=0;
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  if(map[i][j]==1)
	    {
	      c++;
	      //   cout<<i<<"  "<<j<<endl;
	      map_clear(i,j);
	    }
      cout<<c<<endl;
    }
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>n >> m >> k;
  if(k/n- (m-1)/n > 0){
    cr("OK");
  }
  cr("NG");
  
 
}

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


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main() {
	//freopen("/Users/liyingyan/Documents/ACM/in.txt", "r", stdin);
	//std::ios::sync_with_stdio(false);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = min(a, b) + min(c, d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[MAXN];
int a[MAXN],N,M;
struct node {
    int to,next;
}E[MAXN * 10];
int head[MAXN],sumE,sum;
bool vis[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Init() {
    scanf("%s",s + 1);
    N = strlen(s + 1);
    s[0] = 'a';s[N + 1] = 'a';
    for(int i = 1 ; i <= N + 1; ++i) a[i] = (s[i] - s[i - 1] + 26) % 26;
    read(M);
    int L,R;
    for(int i = 1 ; i <= M ; ++i) {
	read(L);read(R);
	add(L,R + 1);add(R + 1,L);
    }
    for(int i = 1 ; i <= N + 1 ; ++i) {
	add(i,N + 2 - i);
    }
}
void dfs(int u) {
    vis[u] = 1;
    sum = (sum + a[u]) % 26;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    dfs(v);
	}
    }
}
void Solve() {
    bool flag = 1;
    for(int i = 1 ; i <= N + 1 ; ++i) {
	if(!vis[i]) {
	    sum = 0;
	    dfs(i);
	    if(sum != 0) {flag = 0;break;} 
	}
    }
    if(flag) puts("YES");
    else puts("NO");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


Measured memory_bytes: 5632
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))

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

int main()
{
    int N;
    cin >> N;
    float ans = 0.0;
    for (int i = 0; i < N; i++)
    {
        float x;
        cin >> x;

        string u;
        cin >> u;

        if (u == "JPY")
        {
            ans += x;
        }
        else
        {
            ans += 380000.0 * x;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256