akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  cin >> n >> s;
  VI fst(10,-1);
  for (int i = 0; i < n; i++)
  {
    if (fst[s[i] - '0'] == -1)
    {
      fst[s[i] - '0'] = i;
    }
  }
  long long ans = 0;
  vector<vector<int>> mem(10, vector<int>(10, -1));
  for (int i = 0; i < 10; i++)
  {
    if (fst[i] == -1)
      continue;
    VI snd(10, -1);
    for (int j = fst[i]+1; j < n; j++)
    {
      if(snd[s[j]-'0']==-1){
        snd[s[j] - '0'] = j;
      }
    }
    for (int j = 0; j < 10; j++)
    {
      if(snd[j]==-1){
        continue;
      }
      VI tmp(10, -1);
      for (int k = snd[j]+1; k < n; k++)
      {
        if (tmp[s[k] - '0'] == -1)
          tmp[s[k] - '0'] = 1;
      }
      for (int k = 0; k < 10; k++)
      {
        if(tmp[k]==1)
          ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct Input{
  int u;
  int k;
  int v[1000];
}input;

int main(void){
  int n,i,j,G[100][100];
  input Adj[100];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d",&Adj[i].u);
    scanf("%d",&Adj[i].k);

    if(Adj[i].k != 0){
      for(j = 0 ; j < Adj[i].k ; j++){
	scanf("%d",&Adj[i].v[j]);
      }
    }
    
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      G[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < Adj[i].k ; j++){
      
      G[Adj[i].u-1][Adj[i].v[j]-1] = 1;
      
    } 
  }
  
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      printf("%d",G[i][j]);
      if(j < n-1){
	printf(" ");
      }
    }
    printf("\n");
  }
 
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s[4];
    scanf("%s",s);
    if(s[0]!=s[1]){
        printf("Yes");
    }else if(s[1]!=s[2]){
        printf("Yes");
    }else if(s[0]!=s[2]){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
#include <complex>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

typedef long long ll;

int days[55];
ll dp[55];

int main(){
    int n,i,j,f;

    while( cin >> n, n ){
        memset(days, 0, sizeof(days));
        rep(i,n) dp[i] = 1LL << i;

        rep(i,n){
            cin >> f;
            rep(j,f){
                int d; cin >> d;
                days[i] |= 1<<(d-1);
            }
        }

        rep(i,33){
            ll S = 0;
            rep(j,n){
                if( days[j] & (1<<i) ){ // jlÚÌlªiúÚÌ\èª ¢Äé©
                    S |= dp[j];
                }
            }
            if( S == (1LL<<n) - 1 ) break;
            rep(j,n) if( days[j] & (1<<i) ) dp[j] = S;

            // debug
            /*
            printf("days = %d\n",i);
            rep(j,n){
                printf("%d : %lld\n",j,dp[j]);
            }
            */
        }

        printf("%d\n",i == 33 ? -1 : i+1);
    }

    return 0;
}

Measured memory_bytes: 872
from collections import deque

S = input()

Sint = int(S,2)
Slen = len(S)

def create_wbint(l, start_with_white=True):
    is_white = start_with_white
    wbdeque = deque([])
    for i in range(l):
        if is_white:
            wbdeque.append('0')
        else:
            wbdeque.append('1')
        is_white = not is_white
    return int(''.join(wbdeque),2)


WBint = create_wbint(Slen, start_with_white=True)
BWint = create_wbint(Slen, start_with_white=False)

WBxor = Sint ^ WBint
count_1_in_wb = 0
for c in bin(WBxor):
    if c == '1':
        count_1_in_wb +=1

BWxor = Sint ^ BWint
count_1_in_bw = 0
for c in bin(BWxor):
    if c == '1':
        count_1_in_bw +=1

print(min(count_1_in_wb, count_1_in_bw))


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

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

	float howMuch;
	string type;

	float total = 0.0f;

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

		if (type == "JPY")
		{
			total += howMuch;
		}
		else
		{
			total += howMuch * 380000.0f;
		}
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (B < A) {
			int temp = B;
			B = A;
			A = temp;
		}

		if (A < C && C < B) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	private static class Tuple {
		boolean hasLeft;
		boolean hasRight;
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 21460
#include<stdio.h>
int main(void){
  int i,n,m,a[100],s=0,q=0;
  scanf("%d%d", &n, &m);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    s=s+a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]*4*m>=s){
      q++;
    }
  }
  if(q>=m){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
import math
PI = 3.141592653589793
def degRad(deg):
	return deg * PI / 180.0

a, b, H, M = map(float, input().split())
time = H + M / 60.0

hAngle = 2.0 * PI * time / 12.0
y1 = a * math.cos(hAngle)
x1 = a * math.sin(hAngle)

mAngle = 2.0 * PI * time
y2 = b * math.cos(mAngle)
x2 = b * math.sin(mAngle)

dist = math.sqrt(math.pow(x1 - x2, 2) + math.pow(y2 - y1, 2))
print(round(dist, 9))


Measured memory_bytes: 62704
import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))


N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
count=0
for i in range(len(L)-1):
    low=L[i]
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        high = L[j]
        
        #上限を取得
        high_index = bisect.bisect_left(L[j+1:], high+low)
        count+=high_index#len(L[j+1:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))

Measured memory_bytes: 52940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll mx=INT_MAX;
ll mn=INT_MIN;
const ll maxs = 1e3+5;

ll w[maxs];
ll val[maxs];
ll n,sz;
ll solve()
{
    ll dp[n+1][sz+1];
    memset(dp,0,sizeof dp);    
    for(ll i=1;i<=n;i++)
    {
         ll curr_w = w[i];
         ll curr_val = val[i];
        for(ll j=1;j<=sz;j++)
        {
            if(j<curr_w)
            {
                //dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                //dp[i][j] = max(dp[i-1][j],max(dp[i][j-1] ,curr_val + dp[i-1][j-curr_w] ) );
                dp[i][j] = max(dp[i-1][j], curr_val + dp[i-1][j-curr_w]);
            }
        }
    }
    
    /*for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=sz;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;    
    }*/
    
    return dp[n][sz];
}



int main(){
    cin>>n>>sz;
    for(ll i=1;i<=n;i++)
        cin>>w[i]>>val[i];
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 79104
// --------------
// Tejas Pandey  |
// 21 - 03 - 20  |
// AtCoder BC 159|
// --------------

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

#define mod 998244353
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  string s;
  cin >> s;
  int n = s.size();
  string k = s;
  reverse(k.begin(),k.end());
  if(k == s);
  else{
  	cout << "No\n";
  	return 0;
  }
  string f = s.substr(0,(n - 1)/2);
  k = f;
  reverse(k.begin(),k.end());
  if(k == f);
  else{
  	cout << "No\n";
  	return 0;
  }
  f = s.substr((n + 3)/2 - 1,n);
  k = f;
  reverse(k.begin(),k.end());
  if(k == f);
  else{
  	cout << "No\n";
  	return 0;
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
def main():
    N, x, *a = map(int, open(0).read().split())
    ans = 0
    pre = a[0]
    for i in range(1, N):
        if x < pre + a[i]:
            cur = pre + a[i] - x
            ans += cur
            a[i] = a[i] - cur if cur < a[i] else 0
        pre = a[i]
    print(ans)
    return


main()


Measured memory_bytes: 14092
A=list(input().split(" "))
B=list(input().split(" "))
for i in range(len(B)):
    B[i]=int(float(B[i]))
C=sorted(B)
D=[]
M=0
for i in range(int(A[1])):
    D.append(int(C[i]))
for j in range(len(D)):
    M=D[j]+M
print(M)

Measured memory_bytes: 9040
N, M, K = list(map(int, input().split()))
p = 998244353
comb = 1
res = 0
for n in range(K+1):
    res = (res + comb * M * pow(M-1, N-1-n, p)) % p
    comb = (comb * (N -1 -n) * pow(n + 1, p - 2, p)) % p
print(res)

Measured memory_bytes: 9204
#include <stdio.h>
#include <algorithm>

#define LIM_S 200002
#define LIM_N 200001
#define DIV 998244353

char str[LIM_S];

int N;
int A[LIM_N];
int max;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
}

void initialize() {
/*
	1 7
	1 2 3 6
	1 2 4 8

	1 2 3 4 6 12
	1 3 5 15
	1 2 3 6 9 18
*/
}

void update_max(int x) {
	max = max > x ? max : x;
}

void search(int x) {
	for (size_t i = 1; i*i <= x; i++) {
		if (x % i == 0) {
			int c = x / i;
			int miss = 0;
			for (size_t j = 0; j < N; j++) {
				if (A[j] % c != 0) {
					miss++;
				}
			}
			if (miss <= 1) {
				update_max(c);
			}

			c = i;
			miss = 0;
			for (size_t j = 0; j < N; j++) {
				if (A[j] % c != 0) {
					miss++;
				}
			}
			if (miss <= 1) {
				update_max(c);
			}
		}
	}
}

int solve() {
	search(A[0]);
	search(A[1]);

	return max;
}

int main(void) {
	receive_input();
	initialize();

	printf("%d\n", solve());

	return 0;
}


Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val l = sc.nextInt()
    val s = (0 until n).map { sc.next() }
    println(problem042b(n, l, s))
}

fun problem042b(n: Int, l: Int, s: List<String>): String {
    return s.sorted().joinToString("")
}

Measured memory_bytes: 37448
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string alp = "abcdefghijklmnopqrstuvwxyz";
    static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static void Main()
    {
      var n = ScanInt();
      var a = ScanIntArray();
      int min = a[0];
      int res = 0;
      for(int i=0; i<n; i++){
        if(min >= a[i]) res++;
        min = Math.Min(min, a[i]);
      }
      WriteLine(res);
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
    static public string RegaxReplace(this string arg1, string pattern, string replacement)
    {
      return Regex.Replace(arg1, pattern, replacement);
    }
  }
  
  static class MyMath {
    public static bool isPrime(this int p){
      if(p<=1) return false;
      for(int i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static bool isPrime(this long p){
      if(p<=1) return false;
      for(long i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 34012
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int D; cin >> D;
    vector<int> C(26); vector<vector<int>> S(D, vector<int>(26));
    REP(i, 0, 26) cin >> C[i];
    REP(i, 0, D) REP(j, 0, 26) cin >> S[i][j];

    vector<int> T(D);
    REP(i, 0, D) cin >> T[i];

    ll ret = 0;
    vector<int> last(26, 0);
    REP(i, 0, D) {
        ret += S[i][T[i] - 1];
        last[T[i] - 1] = i + 1;
        REP(j, 0, 26) {
            ret -= C[j] * (i + 1 - last[j]);
        }
        cout << ret << endl;
    }
    return 0;
}

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

using namespace std;

int n, A[50];

int solve(int i, int m){
    if(m == 0) return 1;
    if(m < 0 || i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    int q, M, i;

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

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> M;
        if(solve(0, M)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
# C - Next Prime
X = int(input())
n = int(10**5)**2
def is_prime(n):
    for k in range(2, n):
        if n % k == 0:
            return False
        else:
            continue
    return True

if is_prime(X) == True:
    print(X)
else:
    for i in range(X+1,n+1):
        if is_prime(i) == True:
            print(i)
            exit()
        else:
            pass

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  ll s1 = 60 * h1 + m1, s2 = 60 * h2 + m2;
  cout << s2 - s1 - k << endl;
}

Measured memory_bytes: 3596
while true do
  n, l = gets.split(' ').map(&:to_i)
  break if n == 0 && l == 0
  array = (1..n).to_a.map do |i|
    d_s, p_s = gets.split(' ')
    p = p_s.to_i
    t, d = (d_s == 'R') ? [l-p, 1] : [p, -1]
    {d: d, t: t, i: i, p: p}
  end
  t_max = array.map{|e| e[:t]}.max
  d_ans = array.select{|e| e[:t] == t_max}.map{|e| e[:d]}.inject(1, :*)
  array_ans = array.each_with_index.map do |e, index|
    left_count = array[0..index].select{|el| el[:d] == 1 && (el[:p]-e[:p]).even?}.count
    right_count = array[index..-1].select{|el| el[:d] == -1  && (el[:p]-e[:p]).even?}.count
    e.merge({d_exit: (left_count - right_count) * 2 -e[:d]})
  end.select{|e| e[:d_exit]*d_ans>0}.select{|e| d_ans==-1 ? (e[:p]+t_max).even? : (e[:p]+l+t_max).even? }
  i_ans = d_ans == 1 ? array_ans[0][:i] : array_ans[-1][:i]
  puts "#{t_max} #{i_ans}"
end

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

int isPrime(int);

int main(){
  int i,n,d;
  int prime_sum=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&d);
    prime_sum += isPrime(d);
  }
  printf("%d\n",prime_sum);
}

int isPrime(int p){
  int sq;
  int i;
  if(p < 2) return 0;
  else if(p == 2) return 1;
  else if(p % 2 == 0)return 0;

  sq = sqrt(p);
  for(i=3; i<=sq; i+=2){
    if(p % i == 0) return 0;
  }
  return 1;
}


Measured memory_bytes: 2084
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = 0;

    ans = (h2 * 60 + m2 - k) - (h1 * 60 + m1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def ti(): return tuple(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(b, r)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def main():
    N = ii()
    A = ti()
    P = 10**9 + 7
    lcm_a = lcm_list(A) % P

    #逆元テーブルの作成
    N = 10**6+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

    ans = 0
    for num in A:
        ans = (ans + inv_t[num] * lcm_a) % P
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 43740
import math

S =  list(map(int,input().split()))
K = S[0]
N = S[1]
P =  list(map(int,input().split()))
R = []
for i in range(len(P)):
    if i >= 1:
        X = P[i]-P[i-1]
        R.append(X)
        if i == N-1:
            X = K + P[0] - P[i]
            R.append(X)
B = max(R)
answer = K-B        
print(answer)
        

Measured memory_bytes: 26444
import copy

H,W,K = map(int, input().split())
matrix = []
for _ in range(H):
    matrix.append(list(input()))

ans = 0
for bitrow in range(2**H):
    c1 = copy.deepcopy(matrix)
    for i in range(H):
        if bitrow >> i & 1:
            for column in range(W):#i行目を全て . に置換
                c1[i][column] = '.'
        
    for bitcolumn in range(2**W):
        c2 = copy.deepcopy(c1)
        for j in range(W):
            if bitcolumn >> j & 1:
                for row in range(H):#j列目を全て . に置換
                    c2[row][j] = '.'
                        
        # '#'の数を数える
        black = 0
        for row in c2:
            for st in row:
                if st == '#':
                    black += 1
        
        if black == K:
            ans += 1
print(ans)

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (a >= k) {
        std::cout << k << endl;
        return 0;
    } else {
        ans = a;
    }

    k -= a;

    if (b >= k) {
        cout << ans << endl;
        return 0;
    }

    k -= b;
    ans -= k;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
 
int main(void){
    ll n,t[200];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    ll ans=t[0];
    for(int i=1;i<n;i++){
        ll a=gcd(ans,t[i]);
        t[i]/=a;
        ans*=t[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int k;
int f[10][10];
void sol(int step,int k,int las)
{
    if(step==-1) return;
    if(las!=0)
    {
        if(k<=f[step][las-1])
        {
            printf("%d",las-1);
            sol(step-1,k,las-1);
            return;
        }
        k-=f[step][las-1];
    }
    if(k<=f[step][las])
    {
        printf("%d",las);
        sol(step-1,k,las);
        return;
    }
    k-=f[step][las];
    printf("%d",las+1);
    sol(step-1,k,las+1);
}
int main()
{
    scanf("%d",&k);
    for(int i=0;i<10;++i) f[0][i]=1;
    for(int i=1;i<10;++i)
    {
        for(int j=0;j<10;++j)
        {
            f[i][j]=f[i-1][j];
            if(j!=0) f[i][j]+=f[i-1][j-1];
            if(j!=9) f[i][j]+=f[i-1][j+1];
        }
    }
    for(int lim=0;;++lim)
    {
        for(int i=1;i<10;++i)
        {
            if(k<=f[lim][i])
            {
                printf("%d",i);
                sol(lim-1,k,i);
                return 0;
            }
            k-=f[lim][i];
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[4];
		int[] b = new int[4];
		int hit,blow,i;
		
		while(scan.hasNextInt()){
			for(i=0;i<4;i++){
				a[i] = scan.nextInt();
			}
			for(i=0;i<4;i++){
				b[i] = scan.nextInt();
			}
			hit = 0;
			blow = 0;
			
			for(i=0;i<4;i++){
				for(int j=0;j<4;j++){
					if(a[i] == b[j]){
						if(i == j){
							hit++;
						}else{
							blow++;
						}
					}
				}
			}
			
			System.out.println(hit + " " + blow);
		}
	}
}

Measured memory_bytes: 16296
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
#define self nodes[p]
#define ls nodes[p << 1]
#define rs nodes[p << 1 | 1]
struct SegmentTree {
    struct Node {
        int ans, rans;
        double maxx;
    };
    Node nodes[MAXN << 2];
    int tot;
    void build(int l, int r, int p) {
        if (l == r) {
            self.ans = self.rans = 0;
            self.maxx = 0;
            return;
        }
        int mid = (l + r) / 2;
        build(l, mid, p << 1);
        build(mid + 1, r, p << 1 | 1);
        push_up(l, r, p);
    }
    void modify(int x, int l, int r, int p, double v) {
        if (l == r) {
            self.ans = 1;
            self.maxx = v;
            return;
        }
        int mid = (l + r) / 2;
        if (x <= mid)
            modify(x, l, mid, p << 1, v);
        else
            modify(x, mid + 1, r, p << 1 | 1, v);
        push_up(l, r, p);
    }
    int get(int l, int r, int p, double maxxl) {
        if (self.maxx <= maxxl) return 0;
        if (l == r) return self.ans;
        int mid = (l + r) / 2;
        if (ls.maxx <= maxxl) return get(mid + 1, r, p << 1 | 1, maxxl);
        return get(l, mid, p << 1, maxxl) + self.rans;
    }
    void push_up(int l, int r, int p) {
        self.maxx = max(ls.maxx, rs.maxx);
        self.ans = ls.ans;
        self.rans = 0;
        if (ls.maxx >= rs.maxx) return;
        int mid = (l + r) / 2;
        self.rans = get(mid + 1, r, p << 1 | 1, ls.maxx);
        self.ans += self.rans;
    }
};

SegmentTree tree;
char text[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int a, v, b, w;
    scanf("%d%d", &a, &v);
    scanf("%d%d", &b, &w);
    scanf("%d", &n);
    if (w > v || (w == v && a != b)) {
        printf("NO\n");
        return 0;
    }
    if (a == b) {
        printf("YES\n");
        return 0;
    }
    if ((ll)n * (v - w) >= abs(a - b)) {
        printf("YES\n");
        return 0;
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 3776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int n = Integer.parseInt(reader.readLine());
        out.println(factors[n]);
    }

    static String[] factors = { "1", "1", "2", "6", "24", "120", "720", "5040",
            "40320", "362880", "3628800", "39916800", "479001600",
            "6227020800", "87178291200", "1307674368000", "20922789888000",
            "355687428096000", "6402373705728000", "121645100408832000",
            "2432902008176640000" };
}

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

int main() {
  
  string S; cin >> S; int numZero = 0, numOne = 0, ans;
  
  for (int i = 0; i < S.size(); i++) {
    
    if (S.at(i) == '0') numZero++;
    
    else numOne++;
    
  }
  
  ans = min(numZero, numOne) * 2;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
    
    vector<int>dirX={-1,0,1};
    vector<int>dirY={-1,0,1};


    void solve(){
        int n;
        cin>>n;
        if(n==0)
            cout<<1;
        else{
            cout<<0;
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
        //    cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int a[1000000],b[1000000],check;

void migi(int i,int n){
  lp(x,n){
    if(a[x]==0) 1;
    else{
      b[x]+=1;
      b[x+a[x]]-=1;
    }
  }
  for(int x=1;x<n;x++){
    b[x]+=b[x-1];
  }
  lp(x,n){
    if(b[x]>0) 1;
    else{
      check=1;
      return;
    }
  }
  return;
}

int main(){
  int n;
  cin>>n;
  lp(i,n){
    cin>>a[i];
    a[i]/=10;
  }
  check=0;
  migi(0,n);
  if(check==0){
    lp(j,1000000){
      b[j]=0;
    }
    check=0;
    reverse(a,a+n);
    migi(0,n);
    if(check==0){
      cout<<"yes"<<endl;
    }
    else cout<<"no"<<endl;
  }
  else cout<<"no"<<endl;
  
  return 0;
}



Measured memory_bytes: 8176
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll h,w,k;
  cin>>h>>w>>k;
  vstr t(h);
  ll ans=0;
  rep(i,h)cin>>t[i];
  for(ll bit=0;bit<(1LL<<(h+w));bit++){
    vstr x(h);
    x=t;
    rep(i,h+w){     
      if((1LL<<i)&bit){
        if(i<h){
         rep(j,w){
           x[i][j]='6';
         }
        }
        else{
          rep(j,h){
            x[j][i-h]='6';
          }
        }
      }
    }
    ll cu=0;
    rep(i,h)rep(j,w){
      if(x[i][j]=='#'){
        cu++;
      }
    }
    if(cu==k) ans++;
  }
  COUT(ans);
}

Measured memory_bytes: 3624
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}


signed main(){
	string s;cin>>s;
	int w;cin>>w;
	string ans;
	for(int i=0;i<s.size();i+=w) ans+=s[i];
	cout<<ans<<endl;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string s;
	while (cin >> s) {
		vector<string>v;
		v.push_back(s);
		rep(i, 0, 7) {
			string t; cin >> t;
			v.push_back(t);
		}
		char ans;
		rep(i, 0, 8) {
			rep(j, 0, 8) {
				if (v[i][j] == '1') {
					if (j + 1 < 8 && i + 1 < 8 && v[i][j + 1] == '1'&&v[i + 1][j] == '1'&&v[i + 1][j + 1] == '1')ans = 'A';
					else if (i + 3 < 8 && v[i + 1][j] == '1'&&v[i + 2][j] == '1'&&v[i + 3][j] == '1')ans = 'B';
					else if (j + 3 < 8 && v[i][j + 1] == '1'&&v[i][j + 2] == '1'&&v[i][j + 3] == '1')ans = 'C';
					else if (i + 1 < 8 && j + 2 < 8 && v[i][j + 1] == '1'&&v[i + 1][j + 1] == '1'&&v[i + 1][j + 2] == '1')ans = 'E';
					else if (i + 2 < 8 && j + 1 < 8 && v[i + 1][j] == '1'&&v[i + 1][j + 1] == '1'&&v[i + 2][j + 1] == '1')ans = 'F';
					else if (i + 2 < 8 && j - 1 >= 0 && v[i + 1][j] == '1'&&v[i + 1][j - 1] == '1'&&v[i + 2][j - 1] == '1')ans = 'D';
					else if (j - 1 >= 0 && j + 1 < 8 && i + 1 < 8 && v[i][j + 1] == '1'&&v[i + 1][j] == '1'&&v[i + 1][j - 1] == '1')ans = 'G';
					goto here;
				}
			}
		}
	here:;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
// D - Wall
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void warshall_floyd(vvi &C){
	rp(relay,0,C.size()) rp(from,0,C.size()) rp(to,0,C.size())
		C[from][to] = min(C[from][to], C[from][relay] + C[relay][to]);
}

int main(){
	int H,W; cin>>H>>W;
	vvi C(10, vi(10)), A(H, vi(W));
	rp(i,0,10) rp(j,0,10) cin>>C[i][j];
	warshall_floyd(C);
	int ans = 0;
	rp(h, 0, H*W){
		int a; cin>>a;
		if(a >= 0) ans += C[a][1];
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 384
def myfun(c):
	return c[0];

h,w = map(int,input().split())

arr = [];
ans = [];

for i in range(h):

	temp = list(map(int,input().split()))
	arr.append(temp)

count=0;
for i in range(h):
	for j in range(w):

		if arr[i][j]%2==1:
			if j < w-1:
				count+=1
				ans.append( [i+1,j+1,i+1,j+2])
				arr[i][j+1]+=1;
				arr[i][j]-=1;
			elif i < h-1:
				count+=1;
				ans.append( [i+1,j+1,i+2,j+1])
				arr[i][j]-=1;
				arr[i+1][j]+=1;

print(count)
for i in range(count):
	print(*ans[i]);

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

int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<tx-sx;i++){
		cout<<"R";
	}
	for(int i=0;i<ty-sy;i++){
		cout<<"U";
	}
	for(int i=0;i<tx-sx;i++){
		cout<<"L";
	}
	for(int i=0;i<ty-sy;i++){
		cout<<"D";
	}
	cout<<"D";
	for(int i=0;i<tx-sx+1;i++){
		cout<<"R";
	}
	for(int i=0;i<ty-sy+1;i++){
		cout<<"U";
	}
	cout<<"LU";
	for(int i=0;i<tx-sx+1;i++){
		cout<<"L";
	}
	for(int i=0;i<ty-sy+1;i++){
		cout<<"D";
	}
	cout<<"R";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

using namespace std;

static const int maxN = 100;

void printarray(int* array,int length)
{
  for(int i = 0; i < length-1; i++)
  {
    printf("%d ",array[i]);
  }
  printf("%d\n",array[length-1]);
}

void insertionSort(int* array, int length)
{
  printarray(array,length);

  for(int i = 1; i < length; i++)
  {
    int key = array[i];
    int j = i - 1;
    for(; j >= 0 & array[j] > key; j--  )
    {
      array[j+1] = array[j];
    }
    array[j+1] = key;

    printarray(array,length);
  }
  return ;
}
int main()
{
  int N;
  int A[maxN];

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

  insertionSort(A,N);

  return 0;

}



Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    REP(i,30){
        REP(j,30){
            if(i*4+j*7 == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for (auto &e: l) cin >> e;

    int ans = 0;
    int sum = 0;
    while (sum <= x && ans < n) {
        sum += l[ans];
        ++ans;
    }

    if (sum <= x) ++ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int main(){
  string N;
  cin >> N;
  if (N.find("7") == string::npos) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;

int a[N],n,num;
ll ans=0;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",a+i);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	num=a[(n+1)>>1];
	for(int i=1;i<=n;i++) 
		ans+=(ll)abs(num-a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <bitset>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::bitset;

int main()
{
  string S;
  cin >> S;

  int len = S.length();

  long long sum = 0;

  for(int i = 0; i < (1 << (len - 1)); i++) {
    string isPlus = bitset<9>(i).to_string().substr(10 - len);

    string num;
    for(int j = 0; j < 2 * len - 1; j++) {
      if(j % 2 == 0) {
        num += S[j / 2];
      } else {
        if(isPlus[floor(j / 2)] == '1') {
          sum += stoll(num);
          num.clear();
        }
      }
    }
    sum += stoll(num);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right,bisect
n=int(input())
ans=defaultdict(lambda:0)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            ans[x*x +y*y +z*z +x*y +y*z+x*z]+=1
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 11764
#include<iostream>
using namespace std;
int main()
{
  char s[4];
  for(int i=0;i<4;i++)
    cin>>s[i];
  int val=0;
  for(int i=0;i<4;i++)
  {
    if(s[i]=='+')
      val++;
    else
      val--;
  }
  cout<<val<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#pragma warning(disable : 4996);
#define nptr nullptr
using namespace std;
typedef long long ll;

const int maxn = (int)1e3 + 13;
const ll INFL = 9223372036854775807;
const int INF = 2147483647;
const ll MOD = (int)1e9 + 7;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll b = 101;
const long double pi = 3.1415926535897932;
ll sum(ll a, ll b) {
	return (a + b) % MOD;
}
ll r(ll a, ll b) {
	return (a - b + MOD) % MOD;
}
ll mult(ll a, ll b) {
	return (a * b) % MOD;
}
int main() {
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
		
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int i = k; i <= n + 1; ++i) {
		ans = sum(ans + 1, r(mult(i, n), mult(i, i - 1)));
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

bool check(string s){
//    cout<<s<<"\n";
    int n=s.size();
    for(int i=0;i<n/2;i++)
        if(s[i]!=s[n-1-i])
            return false;
    return true;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(check(s) && check(s.substr(0,(n-1)/2)) && check(s.substr((n+3)/2 -1)))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
/*
	author: parv2809
*/

#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

}

int dp1[100005];
int dp2[100005];
int m;
void solve1(vector<vector<int> >& tree, vector<bool>& visited, int curr_node) {
	visited[curr_node] = true;
	int ans = 1;
	for (auto child : tree[curr_node]) {
		if (!visited[child]) {
			solve1(tree, visited, child);
			ans *= (1 + dp1[child]);
			ans %= m;
		}
	}
	dp1[curr_node] = ans;
	dp1[curr_node] %= m;
}

void solve2(vector<vector<int> >& tree, vector<bool>& visited, int curr_node, int parent_answer) {

	visited[curr_node] = true;
	dp2[curr_node] = (1 + parent_answer) * dp1[curr_node];
	dp2[curr_node] %= m;

	vector<int> prefix, suffix;
	for (auto child : tree[curr_node]) {
		if (!visited[child]) {
			prefix.pb((1 + dp1[child]));
			suffix.pb((1 + dp1[child]));
		}
	}
	for (int i = 1; i < prefix.size(); i++) {
		prefix[i] *= prefix[i - 1];
		prefix[i] %= m;
	}
	for (int i = suffix.size() - 2; i >= 0; i--) {
		suffix[i] *= suffix[i + 1];
		suffix[i] %= m;
	}
	int node_no = 0;
	for (auto child : tree[curr_node]) {
		if (!visited[child]) {
			int ways = (1 + parent_answer);
			ways = (node_no > 0) ? (ways * prefix[node_no - 1]) % m : ways;
			ways = (node_no < suffix.size() - 1) ? (ways * suffix[node_no + 1]) % m : ways;
			solve2(tree, visited, child, ways);
			node_no++;
		}

	}
}

int32_t main() {

	fastIO();
	int t = 1;
	w(t) {
		int n;
		cin >> n >> m;
		vector<vector<int> > tree(n);
		int a, b;
		for (int i = 0; i < n - 1; i++) {
			cin >> a >> b;
			a--; b--;
			tree[a].pb(b);
			tree[b].pb(a);
		}

		vector<bool> visited(n, false);
		solve1(tree, visited, 0);

		for (int i = 0; i < n; i++) {
			// cout << dp1[i] << " ";
			visited[i] = false;
		}

		solve2(tree, visited, 0, 0);
		for (int i = 0; i < n; i++) {
			cout << dp2[i] % m << endl;
		}
	}

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 27464
def main():
    n,m=map(int,input().split())
    a=[list(map(int,input().split())) for _ in  range(m)]
    a=[[a[i][0],str(a[i][1])] for i in range(m)]
    
    if n==1:
        s=0
        f=10
    else:
        s=10**(n-1)
        f=10**n
        
    for num in range(s,f):
        num=str(num)
        flag=True
        for i in range(m):
            #print(1)
            if num[a[i][0]-1]!=a[i][1]:
                flag=False
                break
                
        if flag:
            print(int(num))
            exit()
    print(-1)     
   
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);
int min(int, int);

P Q[LEN+1];
int head, tail, n;


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}



Measured memory_bytes: 11844
import java.util.*;

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

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

    if ((a * b) % 2 == 1) {
      System.out.println("Odd");
    } else {
      System.out.println("Even");
    }
  }
}

Measured memory_bytes: 25684
#include<stdio.h>
#define N 100000



int partition(int *A,int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      t=A[j];
      A[j]=A[i];
      A[i]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

      
int main(){

  int i,j,n,A[N],w;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
    w= partition(&A[0],0,n-1);

  
for(i=0;i<n;i++){
  if(i<w){
    printf("%d ",A[i]);
  }
  else if(i==w){
      printf("[");
      printf("%d",A[i]);
      printf("]");
    }
    else{
      printf(" %d",A[i]);
    }
  }
 
printf("\n");
return 0;
}

Measured memory_bytes: 992