akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,q,ans=-1e9-7;
int now[100005];

struct node
{
	int a,b,c,d;
}que[100005];

signed main()
{
	cin>>n>>m>>q;
	for (int i=1;i<=q;i++)  cin>>que[i].a>>que[i].b>>que[i].c>>que[i].d;
	for (int i=1;i<=n;i++)  now[i]=1;
	
	while (now[0]==0)
	{
		int sumv=0;
		for (int i=1;i<=q;i++)
		{
			if (now[que[i].b]-now[que[i].a]==que[i].c)  sumv+=que[i].d;
		}
		ans=max(ans,sumv);
		
		for (int i=n;i>=0;i--)
		{
			if (now[i]<m)
			{
				 now[i]++;
				 for (int j=i+1;j<=n;j++)  now[j]=now[j-1];
				 break;
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,m;
	cin>>n>>m;
	char a[50][50],b[50][50];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)cin>>a[i][j];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++)cin>>b[i][j];
	}
	bool ans=false;
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			bool flag=true;
			for(int k=0;k<m;k++){
				if(!flag)break;
				for(int l=0;l<m;l++){
					if(a[k+i][l+j]!=b[k][l]){
						flag=false;
						break;
					}
				}
			}
			if(flag){
				ans=true;
				break;
			}
		}
		if(ans)break;
	}
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());

        int area = a * b;
        int permimeter = 2 * a + 2 * b;

        System.out.println(area + " " + permimeter);
    }
}

Measured memory_bytes: 25960
#include <string.h>
#include <cstring>
#include <cmath>
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
	long int n,i;
	cin>>n;
	for(i=n;i>0;i--)
	{
		int s = sqrt(i);
		if(s*s == i)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = [0] + gets.split.map(&:to_i)

b = Array.new(n + 1)
ans = []

(n / 2 + 1).upto(n) do |i|
  b[i] = a[i]
  ans << i if a[i] == 1
end


(n / 2).downto(1) do |i|
  sum = 0
  pos = i * 2
  while pos <= n do
    sum += b[pos]
    pos += i
  end
  if a[i] == 0 && sum % 2 == 0
    b[i] = 0
  elsif a[i] == 0 && sum % 2 == 1
    b[i] = 1
    ans << i
  elsif a[i] == 1 && sum % 2 == 0
    b[i] = 1
    ans << i
  elsif a[i] == 1 && sum % 2 == 1
    b[i] = 0
  end
  unless b[i]
    pp a[i]
    pp sum
  end
end

puts ans.size
puts ans.join(' ') if ans.size > 0

Measured memory_bytes: 23500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
  
// syakutori-hou
class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();
  
  
    void solve()
    {
        int N = cin.nextint;
        int Q = cin.nextint;
         
        var A = cin.scanlong;
        var X = cin.scanlong;
         
         
        for(int i = 0; i < Q; i++)
        {
            int high = 0, low = 0; 
            long ans = 0, sum = 0;
             
            while(high < N)
            {
                sum += A[high++];
                 
                while(sum > X[i])
                {
                    sum -= A[low++];
                }
                ans += high - low;
            }
            Console.WriteLine(ans);
        }
         
         
    }
  
}
  
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 17584
import bisect
n,m = map(int,input().split())
l = []
for i in range(1,int(m**0.5)+1):
    if m%i == 0:
        l.append(i)
        l.append(m//i)

l.sort()
for i in range(len(l)-1,-1,-1):
    if l[i] <= m//n:
        print(l[i])
        exit()

Measured memory_bytes: 3188
//
//AtCoder Beginner Contest 179
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    string ans = "No";

    int cnt = 0;
    REP(i, n) {
        int d1,d2;
        cin >> d1 >> d2;
        if (d1 == d2) {
            cnt++;
            if (cnt==3){
                ans="Yes";
            }
        }
        else cnt = 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val (n, y) = readLine()!!.split(" ").map{ it.toInt() }
    val heightOfN = readLine()!!.split(" ").map{ it.toInt() }
    var badOfN  = mutableSetOf<Int>()
    for (i in 0 until y){
        val (x, y) = readLine()!!.split(" ").map{ it.toInt() }
        if (heightOfN[x - 1] >= heightOfN[y - 1])  {
            badOfN.add(y)
        }
        if (heightOfN[x - 1] <= heightOfN[y - 1])  {
            badOfN.add(x)
        }
    }
    println(n - badOfN.size)
}


Measured memory_bytes: 75412
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(1<<30)-1;
const ll INFl=9223372036854775807;
const int MAX=310;
const ll MOD=1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll k,n,cnt,tmp,ans;
typedef pair<ll,ll> P;
vector<P> v;
bool flag[100010];
priority_queue<ll,vector<ll>,greater<ll>> pq;

int main(){
	speed_up
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll s,t;
		cin>>s>>t;
		v.push_back(P(t,s));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=0;i<k;i++){
		if(!flag[v[i].second]){
			tmp+=v[i].first;
			++cnt;
			flag[v[i].second]=true;
		}else{
			tmp+=v[i].first;
			pq.push(v[i].first);
		}
	}
	ans=tmp+cnt*cnt;
	for(int i=k;i<n;i++){
		if(pq.empty())
			break;
		if(!flag[v[i].second]){
			flag[v[i].second]=true;
			ll p=pq.top();
			pq.pop();
			tmp-=p;
			tmp+=v[i].first;
			cnt++;
			ans=max(ans,tmp+cnt*cnt);
		}
	}
	cout<<ans<<endl;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vp;
typedef vector<ll> vll;

const int INF = 99999999;
const int MAX_V = 100000;

struct edge { int to, cap, cost, rev; };

int V, E, F;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V]; // privious vertex, edge

void add_edge(int from, int to, int cap, int cost) {
    G[from].emplace_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

// get min cost flow from s to t
// if we can flow not at all, then return -1
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    while (f > 0) {
        fill(dist, dist + V, INF);
        dist[s] = 0;
        bool update = true;
        while (update) {
            update = false;
            rep(v, V) {
                if (dist[v] == INF) continue;
                rep(i, G[v].size()) {
                    edge &e = G[v][i];
                    if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }

        if (dist[t] == INF) {
            // no more flow
            return -1;
        }

        // flow as much as possible along minimum path from s to t
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, (int)G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * dist[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

signed main() {
    cin >> V >> E >> F;
    rep(i, E) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        add_edge(u, v, c, d);
    }

    cout << min_cost_flow(0, V - 1, F) << endl;
}

Measured memory_bytes: 5552
/*
cat <<EOF >mistaken-paste
*/

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define BIG 2000000007
#define VERYBIG 200000000000007LL

#define MOD 1000000007
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 2000
#define M_MAX 200000

typedef struct {
	int32_t a;
	int32_t b;
} hw;

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	hwll a;
	hwll b;
} linell;


typedef struct {
	ull s;
	ull t;
	int32_t c;
} struct_a;

typedef struct {
	int32_t from;
	int32_t to;
	sll cost;
} struct_b;

ull n, m;
ull h, w;
ull k;
ull q;
ull vua, vub, vuc, vud, vue, vuf;
sll vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull umax (ull x, ull y) {
	return (x > y) ? x : y;
}

sll smin (sll x, sll y) {
	return (x < y) ? x : y;
}

sll smax (sll x, sll y) {
	return (x > y) ? x : y;
}

ull bitpow (ull a, ull x, ull modulo) {
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= modulo;
		}
		x /= 2;
		a = (a * a) % modulo;
	}
	return result;
}

ull divide (ull a, ull b, ull modulo) {
	return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}

ull dp[N_MAX + 1];
ull amazing[N_MAX + 100];
ull npkdp[N_MAX + 1][N_MAX + 1];
ull division[N_MAX + 1][N_MAX + 1];

ull npk (ull n, ull k) {
	return divide(amazing[n], amazing[n - k], MOD);
}

ull grouping (sll whole, sll members, sll parts) {
	// whole_P_(mem*par)/(members!)^parts / parts!
	if (!division[members][parts]) {
		division[members][parts] = (bitpow(amazing[members], parts, MOD) * amazing[parts]) % MOD;
	}
	return divide(npk(whole, members * parts), division[members][parts], MOD);
}

ull solve () {
	sll i, j, ki;
	// ull result = 0;
	sll result = 0;
	// double result = 0;
	ull maybe = 0;
	// sll maybe = 0;
	ull sum = 0;
	// sll sum = 0;
	ull item;
	ull *dpcell;

	time_t start = time(NULL);

	amazing[0] = 1;
	for (i = 1; i <= n; i++) {
		amazing[i] = (amazing[i - 1] * i) % MOD;
	}
	// printf("%u...\n", time(NULL) - start);

	sll latest = n;
	dp[n] = 1;

	for (i = vua; i <= vub; i++) {
		latest = smax(latest - i * vud, 0);
		for (j = latest; j + i * vuc <= n; j++) {

			for (ki = vuc; ki <= vud; ki++) {
				sll xi = j + i * ki;
				if (xi > n) break;
				if (!dp[xi]) continue;

				dp[j] += dp[xi] * grouping(xi, i, ki);
				dp[j] %= MOD;
			}
			// printf("[%lld]; %llu\n", j, dp[j]);
		}
		// if (i <= 50 || i % 50 == 0) {
		// 	printf("(time: %u) ", time(NULL) - start);
		// 	printf("%lld... [0]:%llu\n", i, dp[0]);
		// 	fflush(stdout);
		// }
	}
	result = dp[0];

	printf("%llu\n", result);

	return 0;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	scanf("%llu", &n, &m);
	scanf("%llu%llu%llu%llu", &vua, &vub, &vuc, &vud, &vue, &vuf);

	solve();

	return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	string str; cin >> str;
	int cnt = 0,maxx=0;
	int a=200000,z=0;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] =='A') {
			a = min(a, i);
		}
		if (str[i] == 'Z') {
			z = max(z, i);
		}
	}
	cout << z-a+1;

	cout << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
  while(1) {
    int m, f, r, score;
    scanf("%d %d %d\n", &m, &f, &r);
    if ((m == -1) && (f == -1) && (r == -1))
      break;
    if ((m == -1) || (f == -1)) printf("F\n");
    else {
      score = m + f;
      if (score >= 80)       printf("A\n");
      else if (score >= 65)       printf("B\n");
      else if (score >= 50)       printf("C\n");
      else if (score >= 30) {
        if (r >= 50)              printf("C\n");
        else                      printf("D\n");
      }
      else                        printf("F\n");
    }
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,a,b,sumv=0;

signed main()
{
	cin>>n>>a>>b;
	cout<<(1ll*n/(1ll*a+1ll*b))*a*1ll+min((1ll*n%(1ll*a+1ll*b)),1ll*a)<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }

struct unionfind {
    vector<int> par;
    vector<int> sizes;

    unionfind(int n) : par(n),sizes(n,1){
        rep(i,0,n) par[i] = i;
    }

    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x,int y){
        x = root(x);
        y = root(y);

        if(x == y) return;

        if(sizes[x] < sizes[y] ) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return;
    }

    bool same(int x,int y){
        return root(x) == root(y);
    }

    int size(int x){
        return sizes[root(x)];
    }
};

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    unionfind uf(n);
    vector<ll> vec1[n],vec2[n];

    ll a,b;
    rep(i,0,m){
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
        vec1[a].push_back(b);
        vec1[b].push_back(a);
    }

    rep(i,0,k){
        cin >> a >> b;
        a--;b--;
        vec2[a].push_back(b);
        vec2[b].push_back(a);
    }

    rep(i,0,n){
        ll temp = 0;
        rep(j,0,sz(vec1[i])) if(uf.same(i,vec1[i][j])) temp++;
        rep(j,0,sz(vec2[i])) if(uf.same(i,vec2[i][j])) temp++;
        cout << uf.size(i) - temp - 1 << ((i == n-1)?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 16092
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
   int n;
   ll k;
   cin >> n >> k;
   VI p(n);
   vector<ll> c(n);
   ll ans=-pow(10,17);
   rep(i,n)cin >> p.at(i);
   rep(i,n){
     cin >> c.at(i);
     ans=max(ans,c.at(i));
   }
   rep(i,n){
   ll scr=0;
   ll ans1=-1*pow(10,13);
   ll ansfin=0;
   ll ms=i+1;
   ll m=0;
   bool a=false;
      rep(j,k){
        m++;
        ms=p.at(ms-1);
        scr+=c.at(ms-1);
        ans1=max(ans1,scr);
        if(i+1==ms){
          a=true;
          break;
        }
      }
      if(a){
          if(scr<=0)ansfin=ans1;
          else{
            ll b=k/m;
            ll d=k%m;
            ansfin+=(b-1)*scr;
            ll mss=i+1;
            ll ans2=0;
            ll scr1=0;
            rep(j,m+d){
              mss=p.at(mss-1);
              scr1+=c.at(mss-1);
              ans2=max(ans2,scr1);
            }
            ansfin+=ans2;
          }
      }
      else{
        ansfin=ans1;
      }
      ans=max(ans,ansfin);
   }
   cout << ans << endl;
}



    
   


Measured memory_bytes: 3656
import java.util.*;

class Main {
	static final Integer ZERO = Integer.valueOf(0);
	Scanner sc;
	int N, K;
	HashMap<Integer, Integer> h;
	int[] S;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		S = new int[N+1];
		h = new HashMap<>(N*4/3);
		
		S[0] = 0;
		for (int i = 1; i < N+1; i++)
			S[i] = (int)(((long)S[i-1] + (sc.nextInt() - 1))%K);
		long cnt = 0;
		for (int i = 1; i < N+1; i++) {
			h.put( S[i-1], h.getOrDefault(S[i-1], ZERO) + 1);
			if (i >= K) {
				int v = h.get(S[i-K]);
				if (v > 1) h.put(S[i-K], v-1);
				else h.remove(S[i-K]);
			}
			cnt += h.getOrDefault(S[i], ZERO);
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


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

using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
ll m, n;

ll sum[N];
ll a[N];
ll k;

map<ll, ll> ma;
// (sum[r] - sum[l -1]) % k == r - l + 1;

int main()
{
	scanf("%lld%lld", &n, &k);
	for (int i = 1; i <= n; i ++)
	{
		scanf("%lld", &a[i]);
		sum[i] = (sum[i - 1] + a[i]);
	}
	for (int i = 1; i <= n; i ++)
	{
		sum[i] = (sum[i] - i) % k;
	}
	ll ans = 0;
	ma[sum[0]] ++;
	for (int i = 1; i <= n; i ++)
	{
		if(i >= k) ma[sum[i - k]]--;
		ans += ma[sum[i]];
		ma[sum[i]] ++;
	}
	cout <<ans << endl;
}


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

int main()
{
	string S = "abcdefghijklmnopqrstuvwxyz";
	char C;
	cin >>C;

	rep(i, S.size()){
		if(C==S.at(i)){
			cout <<S.at(i+1) <<endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}

int main(void)
{
    ll n, ans;
    cin >> n;
    vector<ll> t(n);
    rep(i,n) cin >> t[i];
    ans = t[0];
    REP(i,1,n) ans = lcm(ans, t[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <string>
#include <queue>
using namespace std;
#pragma warning (disable: 4996)

int N, A[19];
vector<pair<int, int>> Z[19];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		for (int j = 0; j < A[i]; j++) {
			int p1, p2; cin >> p1 >> p2; p1--;
			Z[i].push_back(make_pair(p1, p2));
		}
	}

	int maxn = 0;
	for (int i = 0; i < (1 << N); i++) {
		int bit[19], cnt = 0;
		for (int j = 0; j < N; j++) { bit[j] = (i / (1 << j)) % 2; cnt += bit[j]; }

		bool flag = false;
		for (int j = 0; j < N; j++) {
			if (bit[j] == 0) continue;
			for (pair<int, int> k : Z[j]) {
				if (bit[k.first] != k.second) flag = true;
			}
		}
		if (flag == false) maxn = max(maxn, cnt);
	}

	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

void END(){cout << "No" << endl; exit(0);}

int fact(int m)
{
  if (m == 0) return 1.0;
  return m * fact(m-1);
}

int main()
{
 cin.tie(0);
 ios::sync_with_stdio(false);
 int n;
 cin >> n;
  vector<pair<double, double>> town(n);
 INPUTP(town);
 vector<int> v(n);
 iota(v.begin(), v.end(), 0);
 double ans = 0;
 do {
        VI jun(n);
        int idx = 0;
        for(auto x : v)
        {
          jun[idx] = x;
          idx++;
        }
        REP(i, n-1)
        {
            double x1 = town[jun[i]].first;
  double y1 = town[jun[i]].second;
  double x2 = town[jun[i+1]].first;
  double y2 = town[jun[i+1]].second;
  ans += sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }
    } while( next_permutation(v.begin(), v.end()) );
 cout << setpre(10) << ans / (double)fact(n) << endl;

 return 0;
}

Measured memory_bytes: 256
n,m,s,t=map(int,input().split())
yen=[[]*(n+1) for i in range(n+1)]
sunuke=[[]*(n+1) for i in range(n+1)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  yen[u].append((a,v))
  yen[v].append((a,u))
  sunuke[u].append((b,v))
  sunuke[v].append((b,u))
  
import heapq
#n:頂点数、m:辺の数　s:始点　es:辺のリスト
def dijkstra(n,m,s,es):
  #used:訪問済みかどうかを確認する　false 使ってない
  used=[False]*(n+1)
  d=[float("INF")]*(n+1)
  d[s]=0
  used[s]=True
  q=[]
  for to in es[s]:
    heapq.heappush(q,to)
  while len(q)>0:
    minedge=heapq.heappop(q)
    v=minedge[1]
    if used[v]==True:
      continue
    cost=minedge[0]
    d[v]=cost
    used[v]=True
    for to in es[v]:
      heapq.heappush(q,(d[v]+to[0],to[1]))
  return d


d_yen=dijkstra(n,m,s,yen)
d_sunuke=dijkstra(n,m,t,sunuke)

ans=[float("INF")]*(n+1)
num=float("INF")
for i in range(n,0,-1):
  num=min(d_yen[i]+d_sunuke[i],num)
  ans[i]=num
  
for j in range(1,n+1):
  print(10**15-ans[j])
  

  

      
  
  

Measured memory_bytes: 84356
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    for(ll r=sqrt(n);r>0;r--){
        if(n%r==0){
            ll l=n/r;
            cout<<r+l-2<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <fstream>
 
using namespace std;
 
#define INF 100000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;

#define MAX_N 100

int n;
string f[MAX_N];

vector<int> ans_list;

int main(){

  while(true){
    cin >> n;
    if(n == 0)
      break;

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

    int ans = 0;

    int mode = 1; //0:床
    int r = 0;
    int l = 0;

    for(int i = 0; i < n; i++){
      if(f[i] == "lu")
	l = 1;
      else if(f[i] == "ru")
	r = 1;
      else if(f[i] == "ld")
	l = 0;
      else
	r = 0;

      if(mode == l && mode == r && mode == 1){
	ans++;
	mode = 0;
      }

      else if(mode == l && mode == r && mode == 0){
	ans++;
	mode = 1;
      }

    }

    ans_list.push_back(ans);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 1236
h,w,k = gets.split.map(&:to_i)

def hoge(digit, from_w, to_w)
  from = ("0" * digit).to_i(2)
  to = ("1" * digit).to_i(2)
  count = 0
  (from..to).each do |i|
    bit = i.to_s(2).rjust(digit, "0")
    next if bit.include?("11")
    next if (from_w - to_w).abs >= 2
    right = from_w == bit.length ? nil : bit[from_w]
    left = from_w == 0 ? nil : bit[from_w - 1]
    direction = if to_w < from_w
                  count += 1 if left == "1" && right != "1"
    elsif to_w == from_w
                  count += 1 if left != "1" && right != "1"
    else
                  count += 1 if left != "1" && right == "1"
    end
  end
  count
end

dp = []

h.times do |i|
  dp[i] ||= []
  w.times do |j|
    dp[i][j] ||= 0
    if i == 0
      dp[i][j] = hoge(w-1, 0, j)
    else
      if j == 0
        dp[i][j] += (hoge(w-1, j, j) * (dp[i-1][j] || 0))
        dp[i][j] += (hoge(w-1, j+1, j) * (dp[i-1][j+1] || 0))
      elsif j == w
        dp[i][j] += (hoge(w-1, j-1, j) * (dp[i-1][j-1] || 0))
        dp[i][j] += (hoge(w-1, j, j) * (dp[i-1][j] || 0))
      else
        dp[i][j] += (hoge(w-1, j-1, j) * (dp[i-1][j-1] || 0))
        dp[i][j] += (hoge(w-1, j, j) * (dp[i-1][j] || 0))
        dp[i][j] += (hoge(w-1, j+1, j) * (dp[i-1][j+1] || 0))
      end
    end
  end
end

puts dp[-1][k-1] % 1000000007

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define int long long

string K;
const int M = 1e9 + 7;
int D, mem[10005][105][2];

int dp(int n, int r, bool b) {
	if (n == K.size()) return r == 0;
	if (mem[n][r][b] != -1) return mem[n][r][b];
	int v = 0;
	if (b) {
		for (int i = 0; i <= K[n] - '0'; i++)
			v += dp(n + 1, (r + i) % D, i == K[n] - '0'), v %= M;
	} else {
		for (int i = 0; i <= 9; i++)
			v += dp(n + 1, (r + i) % D, 0), v %= M;
	}
	return mem[n][r][b] = v;
}

int f() {
	int v = 0;
	for (int i = 0; i < K.size(); i++)
		for (int j = 1; j <= (i ? 9 : K[0] - '0'); j++)
			v += dp(i + 1, j % D, (i ? 0 : j == K[0] - '0')), v %= M;
	return v;
}

main() {
	memset(mem, -1, sizeof mem);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> K >> D;
	cout << f() << '\n';
}


Measured memory_bytes: 17408
function Main(input) {
  var input = input.split("\n");
  var string = input[0];
  var answer = "CODEFESTIVAL2016";
  var count = 0;

  for(var i= 0; i < 16; i++){
    if(string.charAt(i) != answer.charAt(i)){
      count++;
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11768
from collections import deque
import sys

ans = []
while True:
    w = input()
    if w =='-':
        break
    w = deque(w)
    m = int(input())
    for _ in range(m):
        shuffle = int(input())
        for __ in range(shuffle):
            w.append(w.popleft())
    ans.append(''.join(w))

for s in ans:
    print(s)


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   if(m==1){
      cout << "0\n";
      return 0;
   }
   int cnt = n;
   int ans = 1;
   while(cnt < m){
      cnt += n-1;
      ans++;
   }
   cout << ans << '\n';
   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;

template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int x;
    cin >> x;
 
    for(int i = -1000; i <= 1000; ++i) {
        ll a5 = 1;
        rep(a, 5) a5 *= i;
        for(int j = -1000; j <= 1000; ++j) {
            ll b5 = 1;
            rep(b, 5) b5 *= j;
            if(a5 - b5 == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}
    

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int par[1010], ran[1010];

void init(int n_) {
	for (int i = 1; i <= n_; i++)par[i] = i, ran[i] = 0;
}

int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (ran[x] < ran[y])par[x] = y;
	else {
		if (ran[x] == ran[y])ran[x]++;
		par[y] = x;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

vector<pair<int, int>> vec[1010];
vector<int> ve;
bool bo;

void dfs(int v, int p, int t) {
	if (bo)return;
	int q = (int)vec[v].size();
	for (int i = 0; i < q; i++) {
		if (vec[v][i].first == p)continue;
		ve.push_back(vec[v][i].second);
		if (vec[v][i].first == t)bo = true;
		dfs(vec[v][i].first, v, t);
		if (bo)break;
		ve.pop_back();
	}
}

const ll mod = 1000000007;

int n, m;
ll x;
pair<int, pair<int, int>> a[2010];
bool bl[2010];
int cntm, cntx, cntp;

signed main() {
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++)cin >> a[i].second.first >> a[i].second.second >> a[i].first;
	sort(a, a + m);
	init(n);
	ll cnt = 0;
	for (int i = 0; i < m; i++) {
		if (!same(a[i].second.first, a[i].second.second)) {
			cnt += a[i].first;
			unite(a[i].second.first, a[i].second.second);
			vec[a[i].second.first].push_back(make_pair(a[i].second.second, a[i].first));
			vec[a[i].second.second].push_back(make_pair(a[i].second.first, a[i].first));
			bl[i] = true;
		}
	}
	for (int i = 0; i < m; i++) {
		if (bl[i])continue;
		bo = false;
		ve.clear();
		dfs(a[i].second.first, 0, a[i].second.second);
		sort(all(ve));
		if (cnt + a[i].first - ve.back() < x)cntm++;
		else if (cnt + a[i].first - ve.back() == x)cntx++;
		else cntp++;
	}
	if (cnt == x)cout << (mod_pow(2, n - 1 + cntx, mod) - 2 + mod) % mod*mod_pow(2, cntp, mod) % mod << endl;
	else cout << (mod_pow(2, cntx, mod) - 1)*mod_pow(2, cntp, mod) * 2 % mod << endl;
}


Measured memory_bytes: 3780
import java.util.*;

public class Main {

    public static void main(String[] args) {
        ArrayDeque<Integer> arrayDeque = new ArrayDeque<>();

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()){
            String kigou = sc.next();
            switch (kigou) {
                case "+": {
                    int a = arrayDeque.pop();
                    int b = arrayDeque.pop();
                    arrayDeque.push(a + b);
                    break;
                }
                case "-": {
                    int a = arrayDeque.pop();
                    int b = arrayDeque.pop();
                    arrayDeque.push(b - a);
                    break;
                }
                case "*": {
                    int a = arrayDeque.pop();
                    int b = arrayDeque.pop();
                    arrayDeque.push(a * b);
                    break;
                }
                default:
                    arrayDeque.push(Integer.parseInt(kigou));
                    break;
            }
        }

        System.out.println(arrayDeque.pop());

    }

}


Measured memory_bytes: 26296
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
#define int long long
typedef vector<int> vll;
typedef vector<vll> vvll;
const int N=2e5+5;

const int MOD=1e9+7;

int power(int x, int p) 
{
    int res = 1;
    while (p) 
   {
        if (p % 2) 
	{
            res = (res * x) % MOD;
            --p;
        }
        else {
            x = (x * x) % MOD;
            p /= 2;
        }
    }
    return res;
}
int invmod(int x) {return power(x,MOD-2);}
int dp[N];
int a[N];
int n,k;

void go(int s,int pre,int p)
{
	if(s>n)
		return;
	dp[s]=min(dp[s],pre+abs(a[p]-a[s]));
	for(int i=1;i<=k;i++)
	{
		go(s+i,dp[s],s);
	}
}
int32_t main()
{
	
	
	cin>>n>>k;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	for(int i=0;i<=n+5;i++)
	{
		dp[i]=LLONG_MAX;
	}
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i+j<=n)
			{
				dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
			}
		}
	}
	cout<<dp[n]<<endl;


}

	
	


	




	


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <random>
#include <limits>
#include <string>
#include <sstream>
#include <functional>
#include <iomanip>

#include <cassert>
#include <cmath>
#include <ctime>

using namespace std;

void solve (istream &cin = std::cin, ostream &cout = std::cout)
{
    int n;

    string str;

    cin >> n >> str;

    int E = count (str.begin (), str.end (), 'E');
    int W = n - E;

    vector<int> ps (str.size () + 1);

    for (int i = 1; i < ps.size (); i++)
        ps[i] = ps[i - 1] + (str[i - 1] == 'W' ? 1 : 0);

    int ans = n;

    for (int i = 0; i < str.size (); i++)
        ans = min (ans, ps[i] + E - (i + 1 - ps[i + 1]));

    cout << ans << endl;
}

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

#ifdef LOCAL
    solve ();

    cout << "clock: " << clock () << endl;
#else
    solve ();
#endif // LOCAL

    return 0;
}


Measured memory_bytes: 1940
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

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

        System.out.println(a >= 13 ? b : a >=6 ? b/2 : 0);

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

#define vin(v, N) for (long long i = 0; i < N; i++) cin >> v.at(i)
#define lin(n) long long n; cin >> n
#define chin(x) char x; cin >> x;
#define sin(s) string s; cin >> s;
#define vlin(v, N) vector<long long> v(N); for (long long i = 0; i < N; i++) cin >> v.at(i)

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


int main(){
    int N, Q;
    cin >> N;
    ll int S[N];
    for(int i = 0; i < N; ++i) cin >> S[i];
    cin >> Q;
    ll int T[Q];
    for(int i = 0; i < Q; ++i) cin >> T[i];

    int ans = 0;
    for(int i = 0; i < Q; ++i){
        int left = 0, right = N;
        while (left < right){
            int m = (left + right)/ 2;
            if(S[m] == T[i]) {
                ans++;
                break;
            }
            if(S[m] > T[i]) right = m;
            else left = m + 1;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> w(n);
  int sum=0;
  rep(i,n){
    cin >> w[i];
    sum+=w[i];
  }

  int ans=99999;

  rep(i,n){
    int suml=0;
    for(int j=0; j<=i; j++)  suml+=w[j];
    int sumr=sum-suml;
    ans=min(ans,abs(sumr-suml));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    string s;
    getline(cin,s);
    F(i,0,s.size()){
        if(s[i]>='a' && s[i]<='z') s[i]=s[i]-'a'+'A';
        else if(s[i]>='A' && s[i]<='Z')s[i]=s[i]-'A'+'a';
    }
    cout << s << endl;
    return 0;
}


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

using namespace std;
int main() {
  long long k;
  string s;

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

  cin >> s;
  cin >> k;

  int n = (int) s.size();
  if (s == string(n, s[0])) {
    cout << n * k / 2 << '\n';
  } else {
    int ans1 = 0;
    for (int i = 0; i+1 < n; i++) {
      if (s[i % n] == s[(i + 1) % n]) {
        ++i;
        ++ans1;
      }
    }
    int ans2 = 0;
    for (int i = 0; i + 1 < 2 * n; i++) {
      if (s[i % n] == s[(i + 1) % n]) {
        ++i;
        ++ans2;
      }
    }
    cout << ans1 + (ans2 - ans1)*(k-1) << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque

N=int(input())
G=[[] for _ in [0]*(N+1)]
for i in range(1,N):
    a,b=map(int,input().split())
    G[a].append((b,i))
    G[b].append((a,i))

root,res=0,0
for i in range(1,N+1):
    tmp=len(G[i])
    if tmp>res:
        res=tmp
        root=i
        
q=deque()
q.append((root,0))
color=[0]*N
D=[N+10]*(N+1)
D[root]=0
while q:
    p,c=q.popleft()
    nc=1
    while G[p]:
        np,ni=G[p].pop()
        if D[np]>D[p]:
            D[np]=D[p]+1
            if nc==c:
                nc+=1
            color[ni]=nc
            q.append((np,nc))
            nc+=1
print(res,*color[1:],sep='\n')

Measured memory_bytes: 98692
#include <iostream>

using namespace std;

int main() {
    int n;
    int *p;
    int answer = 0;

    // input
    cin >> n;
    p = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    // process
    for (int i = 2; i < n; i++) {
        if (p[i - 2] < p[i - 1]) {
            if (p[i - 1] < p[i]) {
                answer++;
            }
        } else if (p[i - 2] > p[i - 1]) {
            if (p[i - 1] > p[i]) {
                answer++;
            }
        }
    }

    cout << answer << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  REP(i,9)REP(j,9){
    int x = i+1;
    int y = j+1;
    cout << x << 'x' << y << '=' << (x*y) << endl;
  }
  return 0;
}

Measured memory_bytes: 1116
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a;
		if(n % 2 == 1){
			a = n * 2;
		}
		else{
			a = n;
		}
		System.out.println(a);
	}
}

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

int main()
{
  ll n, k;
  while (cin>>n>>k){
    if (n == 0) continue;

    ll sum = -INF;
    vector<ll> a(n);
    rep(i, n) cin>>a[i];

    vector<ll> s(n+1, 0);
    rep(i, n) s[i+1] = s[i] + a[i];

    for(int i=0; i < n-k; i ++){
      ll tmp = s[i+k] - s[i];
      if (sum < tmp) sum = tmp;
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 4356
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)
	H := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H[i])
	}
	Amax := make([]int, N)

	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		if Amax[a-1] < H[b-1] {
			Amax[a-1] = H[b-1]
		}
		if Amax[b-1] < H[a-1] {
			Amax[b-1] = H[a-1]
		}
	}
	count := 0
	for i := 0; i < N; i++ {
		if Amax[i] < H[i] {
			count++
		}
	}
	fmt.Println(count)

}


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

a = input().split()

for i in range(len(a)):
    a[i] = int(a[i])

while(sum(a)!=max(a)):
    a = [i for i in a if i != 0]
    a = sorted(a)
    for i in range(len(a)-1):
        a[i+1] = a[i+1]%a[0]

print(a[0])

Measured memory_bytes: 11664
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

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

const int irand(int lo,int hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
    int sign = 1;
    T ret = 0;
    char c;

    do{
        c = getc();
    }while(c == ' ' || c == '\n');
    if(c == '-')sign = -1;
    else ret = c-'0';
    while(1){
        c = getc();
        if(c < '0' || c > '9')break;
        ret = 10*ret + c-'0';
    }
    return sign * ret;
}

inline void ini(int& x){
    x = getnum<int>();
}

inline void scani(int& x){
    scanf("%d",&x);
}

//end of macro

const ll MOD = 998244353;
inline ll addmod(ll a, ll b){
    if(a+b<MOD)return a+b;
    return a+b-MOD;
}
inline ll mulmod(ll a, ll b){
    return (a*b)%MOD;
}
inline ll submod(ll a, ll b){
    return addmod(a, MOD-b);
}

const int N = 305;

string str;
int k;
vi vec;
vi pf;
int n1;

int memo[N][N][N];
int dp(int now, int left, int moves){
    if(moves < 0){
        return 0;
    }
    if(now == vec.size()){
        if(left == 0)return 1;
        else return 0;
    }

    int& ret = memo[now][left][moves];
    if(ret != -1)return ret;

    ret = 0;

    int min_place = max(0, pf[now] - (n1 - left));
    REP(place, min_place, left){
        int nmoves = moves;
        if(place > vec[now]){
            nmoves -= place - vec[now];
        }
        ret = addmod(ret, dp(now+1, left-place, nmoves));
    }
    return ret;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>str>>k;
    int curr = 0;
    FOR(i,str.size()){
        if(str[i] == '1'){
            curr++;
            n1++;
        }else{
            vec.pb(curr);
            curr = 0;
        }
    }
    vec.pb(curr);
    k = min(k, n1);

    pf = vec;
    for(int i=1; i<pf.size(); i++){
        pf[i] += pf[i-1];
    }

    memset(memo, -1, sizeof memo);
    cout << dp(0, n1, k) << endl;

    return 0;
}


Measured memory_bytes: 114492