akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <deque>
#include <math.h>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <stack>
#include<cassert>
#include <cfloat>
#include <list>
using namespace std ;
#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define testMyStupedCode TCF--
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
void ReadFromFile( string name , string extention ){
    string fullPath = name + "." + extention ;
    freopen( fullPath.c_str() , "r" , stdin ) ;
}
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
inline char C(){
    char c ;
    scanf( "%c" , &c ) ;
    return c ;
}
inline ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
long double ModLog(long double base, long double x) {
    return (logl(x) / logl(base));
}

const int N = 1e6;
int n;
int dp[N];
int a[N];
int solve(int idx){
     if(idx == n - 1)
          return 0;
     int &ret = dp[idx];
     if(~ret)
          return ret;
     ret = 1e9 + 5;
     if(idx + 1 < n)
          ret = min(ret, abs(a[idx] - a[idx + 1]) + solve(idx + 1));
     if(idx + 2 < n)
          ret = min(ret, abs(a[idx] - a[idx + 2]) + solve(idx + 2));
     return ret;
}
int main(){
    memset(dp, -1, sizeof(dp));
    n = D();
    for(int i = 0; i < n; ++i)
          a[i] = D();
    printf("%d", solve(0));
}


Measured memory_bytes: 9472
#include <iostream>

using namespace std;

int main() {
	string s;
	cin >> s;
	bool f = 0;
	for (unsigned int i = 0; i < s.length(); i++) {
		if (s[i] == '7') {
			f = 1;
		}
	}
	cout << ((f) ? "Yes\n" : "No\n");
	return 0;
}


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

int main(){
    int n; cin>>n;
    vector<int> frame(n);
    float ave=0;
    for(int i=0; i<n; i++){
        cin>>frame[i];
        ave += frame[i];
    }
    ave = ave/n;
    float std = frame[0];
    int ind = 0;
    for(int i=0; i<n; i++){
        float res = abs(frame[i]-ave);
        if(std>res){
            std = res;
            ind = i;
        }
    }
    cout << ind << endl;
}

Measured memory_bytes: 256
x,k,d = map(int,input().split())
x = abs(x)
n = x//d

if k<n:
  print(x-k*d)
  exit()

if n%2==0:
  if k%2==0:
    ans = x - n*d
  else:
    ans = (n+1)*d - x
else:
  if k%2==1:
    ans = x - n*d
  else:
    ans = (n+1)*d - x
    
print(ans)

Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int n, m, i, j, ii, jj, k;
char a[187][187];
short lin[17][187][187][187], col[17][187][187][187];
int main(){
    cin>> n >> m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cin>> a[i][j];
        }
    }
    for(i = n; i >= 1; i--){
        for(j = m; j >= 1; j--){
            if(j == m || a[i][j + 1] != a[i][j]){
                col[0][i][j][i] = j;
            }
            else{
                col[0][i][j][i] = col[0][i][j + 1][i];
            }
            if(i == n || a[i + 1][j] != a[i][j]){
                lin[0][i][j][j] = i;
            }
            else{
                lin[0][i][j][j] = lin[0][i + 1][j][j];
            }
        }
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            for(ii = i + 1; ii <= n; ii++){
                if(a[i][j] == a[ii][j]){
                    col[0][i][j][ii] = min(col[0][i][j][ii - 1], col[0][ii][j][ii]);
                }
            }
            for(jj = j + 1; jj <= m; jj++){
                if(a[i][j] == a[i][jj]){
                    lin[0][i][j][jj] = min(lin[0][i][j][jj - 1], lin[0][i][jj][jj]);
                }
            }
        }
    }
    if(col[0][1][1][n] == m){
        cout<< 0;
        return 0;
    }
    for(k = 1; k <= 16; k++){
        for(i = 1; i <= n; i++){
            for(j = 1; j <= m; j++){
                for(ii = i; ii <= n; ii++){
                    col[k][i][j][ii] = max(col[k - 1][i][j][ii], col[k][i][j][ii]);
                    if(col[k - 1][i][j][ii] != 0){
                        col[k][i][j][ii] = max(col[k][i][j][ii], col[k - 1][i][ col[k - 1][i][j][ii] + 1 ][ii]);
                    }
                    if(col[k][i][j][ii] != 0){
                        lin[k][i][j][ col[k][i][j][ii] ] = max( (short) ii, lin[k][i][j][ col[k][i][j][ii] ]);
                    }
                }
                for(jj = j; jj <= m; jj++){
                    lin[k][i][j][jj] = max(lin[k - 1][i][j][jj], lin[k][i][j][jj]);
                    if(lin[k - 1][i][j][jj] != 0){
                        lin[k][i][j][jj] = max(lin[k][i][j][jj], lin[k - 1][ lin[k - 1][i][j][jj] + 1 ][j][jj]);
                    }
                    if(lin[k][i][j][jj] != 0){
                       col[k][i][j][ lin[k][i][j][jj] ] = max( (short) jj,  col[k][i][j][ lin[k][i][j][jj] ]);
                    }
                }
            }
        }
        for(i = 1; i <= n; i++){
            for(j = 1; j <= m; j++){
                for(ii = n - 1; ii >= i; ii--){
                    col[k][i][j][ii] = max(col[k][i][j][ii], col[k][i][j][ii + 1]);
                }
                for(jj = m; jj >= j; jj--){
                    lin[k][i][j][jj] = max(lin[k][i][j][jj], lin[k][i][j][jj + 1]);
                }
            }
        }
        if(col[k][1][1][n] == m){
            cout<< k;
            return 0;
        }
    }
}


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

const int INF = 10000000;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> x(n);
    for (size_t i = 0; i < n; i++) cin >> x[i];

    int ans = INF;
    for (size_t i = 1; i <= 100; i++) {
        int work = 0;
        for (size_t j = 0; j < n; j++) {
            work += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, work);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC164B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            int D = int.Parse(input[3]);
            while (A > 0 & C > 0)
            {
                C -= B;
                if (C <= 0)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    A -= D;
                    if (A <= 0)
                    {
                        Console.WriteLine("No");
                    }
                }
            }
        }
    }
}


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

using namespace std;
typedef long long ll;

int main(){
	int a, b, c;
	vector<int> A(3);
	for(int i = 0;i < 3; i++){
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	int temp;
	int cnt = 0;

	if(A[0] % 2 == 0 && A[1] % 2 == 0 || A[0] % 2 != 0 && A[1] % 2 != 0){
		int temp = A[1] - A[0];
		cnt += temp / 2;
	}else{
		A[2]++;
		A[0]++;
		cnt++;
		temp = A[1] - A[0];
		cnt += temp / 2;
	}

	cnt += A[2] - A[1];

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int h,n;
    cin>>h>>n;
    cout<<(h+n-1)/n<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func divisors(n int64) []int64 {
	d := []int64{}
	for i := int64(1); i <= n/i; i++ {
		if n%i == 0 {
			d = append(d, i)
			if i != n/i {
				d = append(d, n/i)
			}
		}
	}
	return d
}

func f(n, k int64) bool {
	for n%k == 0 {
		n /= k
	}
	return n%k == 1
}

func main() {
	var n int64
	fmt.Scan(&n)
	ans := len(divisors(n-1)) - 1

	for _, x := range divisors(n) {
		if x == 1 {
			continue
		}
		if f(n, x) {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a,b,c;
int ans;
int flag;
int main()
{
	cin>>a>>b;
	for(int i=1;i<=3;i++)
		if((a*i*b)%2==1)
		{
			flag=1;
			break;
		}
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
def tc():
    n, k = map(int, input().split())
    stones = list(map(int, input().split()))
    # dp[i]: min cost to get to stone i (0 based)
    INF = float('inf')
    dp = [INF] * n
    dp[0] = 0

    # since from one stone you can go to many
    # try using push dp instead of pull
    for i in range(n):
        for j in range(k + 1):
            if i + j < n:
                dp[i + j] = min(dp[i + j], dp[i] + abs(stones[i + j] - stones[i]))

    print(dp[-1])


tc()


Measured memory_bytes: 84896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int a ,b, c ,d ;
    cin >> a >> b>> c >>d;
    bool flag =false;
    while(1){
        c-= b;
        if(c<=0){
            flag=true;
            break;
        }
        a -= d;
        if(a<=0){
            break;
        }
    }

    if(flag){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

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

void helper(vector<vector<int>> &graph,vector<int> &dp,bool check[],int node)
{
    check[node]=true;
    for(int i=0;i<graph[node].size();i++)
    {
        if(!check[graph[node][i]])
          helper(graph,dp,check,graph[node][i]);

        dp[node]=max(dp[node],1+dp[graph[node][i]]);         
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>> graph(n+1);
    bool check[n+1];
    for(int i = 0 ; i<=n ; i++)
        check[i] =false;
    vector<int> dp(n+1,0);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!check[i])
          helper(graph,dp,check,i); 
    }
     

     int gmax=0;
    for(int i:dp)
     gmax=max(gmax,i); 
    cout<<gmax;
 return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+5;
int dp[N][N];
int path[N][N];
char a[N];
char b[N];
vector<char> ans;
int main(){
    int n,m;
    scanf(" %s %s",a+1,b+1);
    n = strlen(a+1);
    m = strlen(b+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i]==b[j]){
                dp[i][j] = dp[i-1][j-1]+1;
                path[i][j] = 3;
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                if(dp[i-1][j] >= dp[i][j-1])    path[i][j] = 1;
                else                            path[i][j] = 2;
            }
        }
    }
    for(int i=n,j=m;i>0 && j>0;){
        if(path[i][j] == 1)         i--;
        else if(path[i][j] == 2)    j--;
        else if(path[i][j] == 3)    ans.push_back(a[i]),i--,j--;
    }
    reverse(ans.begin(),ans.end());
    for(auto x : ans)   printf("%c",x);
    return 0;
}


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

int main(){
    int W,H,x,y;
    scanf("%d %d %d %d",&W,&H,&x,&y);
    double S =double(W)*double(H)/2;
    printf("%lf ",S);
    double hW=double(W)/2;
    double hH=double(H)/2;
    if((double(x)==hW)&&(double(y)==hH)){
        printf("%d",1);
    }else{
        printf("%d",0);
    }
    return 0;
}

Measured memory_bytes: 128
use proconio::*;
fn main() {
    input! {
        n:i64,
    }
    let mut res = 0i64;
    for i in 1..n {
        if n % i == 0 {
            res += n / i - 1;
        } else {
            res += n / i;
        }
    }
    println!("{}", res);
}


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

vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int n;
vector<int> a;

int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> count(1000001, 0);
    for (auto e : a) {
        count[e]++;
    }
    int ans = 0;
    for (auto e : a) {
        auto div = divisor(e);
        bool sure = true;
        for (auto d : div) {
            int ok = 0;
            if (d == e) {
                ok = 1;
            }
            if (count[d] > ok) {
                sure = false;
                break;
            }
        }
        if (sure) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7984
N,K = map(int, input().split())
d = 10**9+7

A = [i for i in range(N+1)]
A_rev = sorted(A, reverse=True)
ans = 0
dp = {'max':sum(A_rev[0:K]), 'min':sum(A[0:K])}
ans += dp['max'] - dp['min'] + 1
for i in range(K, N+1):
    dp['max'] += A_rev[i]
    dp['min'] += A[i]
    ans += dp['max'] - dp['min'] + 1
print(ans%d)

Measured memory_bytes: 19576
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n;

//inputします
void input() {
	cin >> n;
}

//ライブラリ置き場



//main
int main() {
    input();
	int fo = n / 100;
	int lt = n % 100;
	
	if (fo <= 12 && fo > 0) {
		if (lt <= 12 && lt > 0) {
			cout << "AMBIGUOUS" << endl;
			return 0;
		}
		else {
			cout << "MMYY" << endl;
			return 0;
		}
	}
	else  {
		if (lt <= 12 && lt > 0) {
			cout << "YYMM" << endl;
			return 0;
		}
		else {
			cout << "NA" << endl;
			return 0;
		}
	}
	return 0;
}

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

#define ll long long
#define fi first
#define sec second

ll n,m,k,x,x2,y,y2,sol=-1,rep,cnt,sad;
char c;
string s;
vector <ll> V;
vector <ll> A,B;
vector <ll>::iterator it;

int main()
{
    cin >> n >> m >> k;

    A.push_back(0);
    B.push_back(0);
    for (int i=0;i<n;i++){cin >> x; A.push_back(A[i]+x);}
    for (int i=0;i<m;i++){cin >> x; B.push_back(B[i]+x);}

    for (int i=0;i<=n;i++){
        if (A[i]>k) continue;
        it=upper_bound(B.begin(), B.end(), k-A[i]);
        it--;
        sol=max(sol, (ll)(it-B.begin()+i));
//        cout << *it << " " << A[i] << " " << it-B.begin() << "\n";
    }
    cout << sol;
}



Measured memory_bytes: 7940
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		Set<Integer> start = new HashSet<>();
		Set<Integer> end = new HashSet<>();
		for (int i = 0; i < M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if (a == 1) {
				start.add(b);
			}
			
			if (b == N) {
				end.add(a);
			}
		}
		
		for (Integer a: start) {
			if (end.contains(a)) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		
		System.out.println("IMPOSSIBLE");
	}
	
}

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

int main() {
    string s;
    
    cin >> s;
    if (s[0] != '2') {
        s[0] = '2';
    }
    if (s[1] != '0') {
        s[1] = '0';
    }
    if (s[2] != '1') {
        s[2] = '1';
    }
    if (s[3] != '8') {
        s[3] = '8';
    }
    cout << s << endl;

    return 0;
}

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

int main() {
  double a, sum = 0;
  cin >> a;
  rep(i, a) {
    double num;
    cin >> num;
    sum += 1 / num;
  }
  cout << 1 / sum << endl;
}


Measured memory_bytes: 256
a = int(input())
v = []
v.append(a)
i = 1
while True:
    i += 1
    if a % 2 == 1:
        a = (a * 3) + 1  
    else:
        a = (a//2)

    if a not in v:
        v.append(a)
    else:
        break;

print(i)

Measured memory_bytes: 2940
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N - x + 1):
        z = N - x - y
        if x*10000+y*5000+z*1000 == Y:
            print(x, y, z)
            exit()


print("-1 -1 -1")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int q[1000][1000];
int main(){
int a,b;
  string c[1000],d;
  cin>>a>>b;
  for(int i=1;i<=a;i++){
    cin>>d;
    c[i]='a';
    c[i]+=d;
  }
  for(int i=0;i<=a+1;i++){
    for(int j=0;j<=b+1;j++){
      if(i==0||i==a+1||j==0||j==b+1) cout<<"#";
      else cout<<c[i][j];
    }
    cout<<"\n";
  }
}

Measured memory_bytes: 256
main=do
    s<-getLine
    print $ solve s
solve ('g':ss) = solo 0 ss
solve ('p':ss) = solo (-1) ss
solo n [] = n
solo n ('g':ss) = sole (n,n+1) ss
solo n ('p':ss) = sole (n-1,n) ss
sole (g,p) [] = max g p
sole (g,p) ('g':ss) = solo (max g p) ss
sole (g,p) ('p':ss) = solo (max g p - 1) ss

Measured memory_bytes: 4988
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


int main() {
	#ifndef ONLINE_JUDGE
	//freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int st = 400;
	int n; cin >> n;
	int ans = 0;
	while (st + 199 < n) {
		st += 200;
		ans++;
	}
	
	cout << 8-ans << endl;
	
	

	return 0;
}


Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>

int main() {
	/*
	int n, m;
	scanf("%d%d", &n, &m);
	printf("%d", (n - 1)*(m - 1));
	*/
	char s[200],o[10];
	int l,i;
	s[0] = '\0';
	o[0] = '\0';

	scanf("%s", s);

	l = strlen(s);
	sprintf(o, "%c%d%c", s[0], l-2,s[l-1]);

	printf("%s", o);


	return(0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    while(a != 0){
        vector<int> ans(a+b+c,0);
        int N;
        cin >> N;
        vector<vector<int>> check(N, vector<int> (3));
        vector<int> status(N);
        for(int i=0; i<N; i++){
            for(int j=0; j<3; j++){
                cin >> check[i][j];
                check[i][j]--;
            }
            cin >> status[i];
            if(status[i] == 1){
                for(int j=0; j<3; j++){
                    ans[check[i][j]] = 1;
                }
            }
        }
        for(int i=0; i<N; i++){
            if(status[i] == 0){
                int cnt = 0;
                for(int j=0; j<3; j++){
                    cnt += ans[check[i][j]];
                }
                if(cnt == 2){
                    for(int j=0; j<3; j++){
                        if(ans[check[i][j]] != 1) ans[check[i][j]] = -1; 
                    }
                }
            }
        }
        for(int i=0; i<a+b+c; i++){
            if(ans[i] == -1){
                cout << 0 << enld;
            }else if(ans[i] == 0){
                cout << 2 << enld;
            }else{
                cout << 1 << enld;
            }
        }
        cin >> a >> b >> c;
    }
    return 0;
}


Measured memory_bytes: 3168
import sys
a,b = map(int, sys.stdin.readline().rstrip("\n").split())
ans = 0
for i in range(a,b+1):
    i,n1 = divmod(i, 10)
    i,n2 = divmod(i, 10)
    i,n3 = divmod(i, 10)
    n5,n4 = divmod(i, 10)
    if n1 == n5 and n2 == n4:
        ans += 1
print(ans)

Measured memory_bytes: 67716
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 


#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main() {

    ll a, b, c, d;
     cin>>a>>b>>c>>d;

     ll res = max( a *c , b * d);
     res = max(res, a * d);
     res = max(res, b * c);
     cout<<res<<Endl;

    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

LL rec(int level, LL x) {
    if (level == 0) return 1;

    LL len = (1LL << (level + 1)) - 3;
    LL num_p = (1LL << level) - 1;

    if (x == 1) return 0;
    else if (x <= len + 1) return rec(level - 1, x - 1);
    else if (x == len + 2) return num_p + 1;
    else if (x <= (len + 1) * 2) return num_p + 1 + rec(level - 1, x - len - 2);
    else return num_p * 2 + 1;
}
int main() {
    int n; LL x;
    cin >> n >> x;
    cout << rec(n, x) << endl;
    return 0;
}


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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

#define int ll


const int N = 2e5+33, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <ll> vi;          // #include <ext/rope>
                // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}

int ans[3001];

void solve() {
    int n ,x  , y;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i ++) {
        for(int j = i+1; j <= n; j ++) {
            int dist = j - i;
            chmin(dist , abs(x - i) + abs(y - j) + 1);
            chmin(dist , abs(x - j) + abs(y - i) + 1);
            ans[dist] ++;
        }
    }
    for(int i = 1; i <= n-1; i ++) {
        cout << ans[i] << '\n';
    }
}

main() {
    srand(time(0));
//    ios;
    int tt = 1;
//    cin >> tt;
    while(tt --) {
        solve();
//        brute();
    }
    return 0;
}
/*
2 2
2 1

01
10

01
10
11
*/


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]

    for h in range(N - M + 1):
        for w in range(N - M + 1):
            flag = True
            for i in range(M):
                for j in range(M):
                    if A[h + i][w + j] == B[i][j]:
                        continue
                    else:
                        flag = False
                        break
                if not flag:
                    break
            if flag:
                print("Yes")
                return
    else:
        print("No")


main()


Measured memory_bytes: 3188
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int M = sc.nextInt();
	int[] like = new int[M];
	for(int i = 0; i<N; i++) {
	    int k = sc.nextInt();
	    for(int j = 0; j<k; j++) {
		like[sc.nextInt()-1]++;
	    }
	}
	int ans = 0;
	for(int i = 0; i<M; i++) {
	    if(like[i] == N) {
		ans++;
	    }
        }
	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
constexpr int time_limit = 1950;
constexpr int iter_max = 2600000;
chrono::system_clock::time_point start, current;
int c[26];
int64_t s[366][26];


int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t csum = 0;
    for(int i=0;i<26;++i) csum += c[i];
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
    }
    return score;
}

struct simulated_annealing{
    random_device dev;
    mt19937_64 rng;
    uniform_real_distribution<double> dist;
    uniform_int_distribution<int> typ;
    int D;

    simulated_annealing(int d): dist{0.0, 1.0}, typ{0, 25}, D(d){
        rng.seed(1234);
        //rng.seed(dev());
    }

    vector<int> loop(){
        vector<int> state, best_state;
        state.resize(D+1); best_state.resize(D+1);
        for(int i=1;i<=D;++i) state[i] = best_state[i] = typ(rng);
        int64_t curr_score = eval(state, D), best_score = curr_score;

        for(int iter=1;;++iter){
            current = chrono::system_clock::now();
            if(chrono::duration_cast<chrono::milliseconds>(current-start).count() >= time_limit) break;
            auto next_state = neighbor(state);
            int64_t next_score = eval(next_state, D);

            if(next_score >= curr_score || dist(rng) <= probability(curr_score, next_score, temperature(iter))){
                curr_score = next_score;
                state = next_state;
                if(best_score < curr_score){
                    best_score = curr_score;
                    best_state = state;
                }
            }
        }
        return best_state;
    }
    vector<int> neighbor(const vector<int> &curr){
        vector<int> ret{curr};
        int x = rand() % D + 1;
        ret[x] = typ(rng);
        return ret;
    }
    double probability(double score1, double score2, double t){
        if(score1 <= score2) return 1.0;
        else return exp((score2 - score1) / t);
    }
    double temperature(int step){
        double x = step * 1.0 / iter_max;
        return (1.0 - tanh(x)) * 1e3;
    }
};

int main(){
    start = chrono::system_clock::now();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    int d;
    cin >> d;
    for(int i=0;i<26;++i) cin >>c[i];
    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) cin >> s[i][j];
    }
    simulated_annealing sa(d);
    auto ans = sa.loop();

    for(int i=1;i<=d;++i) cout << ans[i] + 1 << endl;

    return 0;
}

Measured memory_bytes: 4304
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int d = a%b;
  int e = d;
  int i;
  for(i=0;i<10000;i++){
    if(d%b==c){
      cout << "YES" << "\n";
      return 0;
    }
    d += e;
  }
  cout << "NO" << "\n";
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

    int n;
    cin >> n;
    vi v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    int tm = v[0];
    ll sum = 0;
    for (int i = 1; i < n; ++i)
    {
        if (v[i] <= tm)
        {
            sum += (tm - v[i]);
            v[i] = tm;
        }
        else
            tm = v[i];
    }
    cout << sum << '\n';
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
int a[1000]={0,105,135,165,189,195};
using namespace std;
int main(){
	int i,j,k,n,m,ans=0;
//	freopen("105.in","r",stdin);
//	freopen("105.out","w",stdout);
	scanf("%d",&n);
	if(n<105)cout<<"0";
	else {
		for(i=1;i<=5;i++)
		if(a[i]<=n)ans++;
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, arr[200001];
int main() {
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	lint prev = -1;
	REP(i, N) {
		if (arr[i] > prev + 1) {
			cout << -1 << endl;
			return 0;
		}
		prev = arr[i];
	}	
	arr[N] = 0;
	lint cnt = 0;
	REP(i, N) {
		if (arr[i] + 1 != arr[i + 1]) {
			cnt += arr[i];
		}
	}
	cout << cnt << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	ll n, k;
	cin >> n >> k;
	vvl v(n+5,vl(n+5,0));
	v[0][0]=1;
	FORN(i,1,n){
		v[i][0]=1;
		FORN(j,1,i){
			v[i][j]=(v[i-1][j-1]+v[i-1][j])%MOD;
		}
	}
	// c(n-k+1) * c(k-1,i-1)
	FORN(i,1,k){
		OUT(v[n-k+1][i]*v[k-1][i-1]%MOD);
	}
    return 0;
}

Measured memory_bytes: 34588
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut answers = vec![0; n + 1];
    for i in (1..n + 1).rev() {
        let mut sum = 0;
        for j in 1.. {
            if i * j > n {
                break;
            }
            sum += answers[i * j];
        }
        if sum % 2 != a[i - 1] {
            answers[i] = 1;
        }
    }
    println!("{}", answers.iter().sum::<usize>());
    for (i, &ans) in answers.iter().enumerate() {
        if ans == 1 {
            print!("{} ", i);
        }
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main()
{ 
  int a, a_one, sum_a = -10, min_a_one = 10;

  for (int i = 0; i < 5; i++)
  {
    cin >> a;
    sum_a += ((a - 1) / 10 + 1) * 10;
    min_a_one = min((a % 10 == 0 ? 10 : a % 10), min_a_one);
  }
  cout << sum_a + min_a_one << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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;
    }
}

int main(void)
{
    int D, T, S;
    //string s;
    cin >> D >> T >> S;
    //cin >> s;
    if (D <= T * S)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
<?php
fscanf(STDIN, "%d %d", $n, $m);
for ($i = 0; $i < $m; $i++) {
	fscanf(STDIN, "%d %d %d", $a[$i], $b[$i], $c[$i]);
	$c[$i] = -$c[$i];
}
$p = array_fill(1, $n, PHP_INT_MAX);
$p[1] = 0;
$loop = $n - 1;
while ($loop--) {
	for ($i = 0; $i < $m; $i++) {
		if ($p[$a[$i]] == PHP_INT_MAX) continue;
		$d = $p[$a[$i]] + $c[$i];
		if ($p[$b[$i]] > $d) $p[$b[$i]] = $d;
	}
}
$loop = $n;
$f = array_fill(1, $n, 0);
while ($loop--) {
	for ($i = 0; $i < $m; $i++) {
		if ($p[$a[$i]] == PHP_INT_MAX) continue;
		$d = $p[$a[$i]] + $c[$i];
		if ($p[$b[$i]] > $d) {
			$p[$b[$i]] = $d;
			$f[$b[$i]] = 1;
		}
		if ($f[$a[$i]]) $f[$b[$i]] = 1;
		if ($b[$i] == $n && $f[$n]) break 2;
	}
}
echo $f[$n] ? 'inf' : -$p[$n];

Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int A,B;

	scanf("%d %d", &A, &B);
	
	printf("%d\n", max(A+B,max(A-B,A*B)));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define check(x,y) (x<a[y])
int a[233333];
int main()
{
	//freopen("in.txt","r",stdin);
	int n;scanf("%d",&n);//cerr<<n<<endl;
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);reverse(a,a+n);a[n]=0;
	//f[0][0]=f[i][i] (i,a[i])
	int l=0,r=n;
	while (l+1!=r)
	{
		int mid=(l+r)>>1;
		if (check(mid,mid)) l=mid;else r=mid;
	}
	//f[l][l]
	//if (l+1==a[l+1]) {puts("First");return 0;}
	int x,y;
	for (x=0;;x++) if (!check(l,l+x)) break;
	for (y=0;;y++) if (!check(l+y,l)) break;
	x=x&1;y=y&1;
	puts((x&&y)?"Second":"First");
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	int cnt = 0;
	int ans = 0;
	do {
		int R = 0;
		int L = 1000;
		for (int i = 0; i < M; i++) {
			R = max(R, v[cnt]);
			L = min(L, v[cnt]);
			cnt++;
			cnt %= N;
		}
		ans += R - L;
	} while (cnt);
	cout << ans << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int checkmin(vector<int> &t){
    int ret = 1<<30;
    rep(i,24){
        rep(j,24){
            if(i==j)continue;
            if(t[i]!=1||t[j]!=1)continue;
            ret = min(ret,min(abs(i-j),24-(abs(i-j))));
        }
    }
    return ret;
}

int main(){
    int N;cin >> N;
    vector<int> D(N);
    rep(i,N)cin >> D[i];
    vector<int> cnt(13,0);
    cnt[0]++;
    rep(i,N){
        cnt[D[i]]++;
    }
    
    vector<int> either;
    vector<int> t(25,0);

    int flag0 = 0;
    if(cnt[0]>=2||cnt[12]>=2)flag0=1;
    for(int i=1;i<=11;i++){
        if(!cnt[i])t[i]=0,t[24-i]=0;
        else if(cnt[i]==1)either.push_back(i);
        else if(cnt[i]==2)t[i]=1,t[24-i]=1;
        else flag0=1;
    }
    if(flag0){
        cout << 0 << endl;
        return 0;
    }
    t[0]=cnt[0],t[12]=cnt[12];

    int M = either.size(),res = -1;

    for(int bit=0;bit<(1<<M);bit++){
        rep(i,M){
            if(bit&(1<<i))t[either[i]]=1,t[24-either[i]]=0;
            else t[either[i]]=0,t[24-either[i]]=1;
        }
        res = max(res,checkmin(t));
    }

    cout << res << endl;
    
    return 0;
}

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

using namespace std;
using vi = vector<int>;
using ll = long long;

#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int MOD = 1000000007;

int main() {
  IN(N);

  vi A(N);
  REP(i, N) cin >> A[i];
  SORT(A);
  if (N % 2 == 1) {
    if (A[0] != 0) {
      OUT(0); return 0;
    }
  }
  FOR(i, N%2, N) {
    if (A[i] == A[i+1] && A[i] == i+1) {
      ++i;
      continue;
    }
    OUT(0); return 0;
  }
  ll ans = 1;
  REP(i, N / 2) {
    ans *= 2;
    ans %= MOD;
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    vector<int> x(3);
    int k;
    cin >> x[0] >> x[1] >> x[2] >> k;
    sort(x.begin(), x.end());
    int base = 1;
    rep(i, k) base *= 2;
    x[2] *= base;
    int ans = 0;
    rep(i, 3) ans += x[i];
    cout << ans;
}


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

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

using namespace std;

const int MOD=1000000007;

int main(){
	int h,w,k; cin>>h>>w>>k; k--;

	int dp[101][8]={};
	dp[0][0]=1;
	rep(i,h) rep(j,w) {
		rep(S,1<<(w-1)){
			bool ok=true;
			rep(i,w-2) if((S>>i&3)==3) ok=false;
			if(!ok) continue;

			int j2=j;
			if(j>0 && S>>(j-1)&1) j2--;
			else if(S>>j&1) j2++;
			dp[i+1][j2]=(dp[i+1][j2]+dp[i][j])%MOD;
		}
	}
	cout<<dp[h][k]<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int res = 0;
  
  rep(i, N-2){
    if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C') res++;
  }
  
  cout << res;
  
}

Measured memory_bytes: 256
import random
import time
import copy

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    ans = []    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)
        
    random.seed(10)
    while time.time() - start < 1.9:
        cp = ans.copy()
        last_d = [0 for i in range(26)]
        score2 = 0  
        
        idx1 = random.randint(0,25)
        idx2 = random.randint(0,25)
        if random.randint(0,1):
            d1 = random.randint(0,D-1) 
            d2 = random.randint(0,D-1)
            if idx1 == idx2:
                continue
            if random.randint(0,1):
                ans[d1] = idx1
            else:
                ans[d1] = idx1
                ans[d2] = idx2
             
        #2値入れ替え
        elif random.randint(0,1):           
            d1 = random.randint(0,D-15) 
            d2 = random.randint(d1+1,d1+14)
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp1
            
        #3値入れ替え          
        else:
            d1 = random.randint(0,D-15) 
            d2 = random.randint(d1+1,d1+7)
            d3 = random.randint(d2+1,d2+7) 
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            tmp3 = ans[d3]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp3
                ans[d3] = tmp1
            else:
                ans[d1] = tmp3
                ans[d2] = tmp1
                ans[d3] = tmp2
            
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans = cp.copy()
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 10108