akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N,K;
vector<int> child[100000];
int ans = 0;

int DFS(int v){
    if(child[v].size()==0)return 0;
    int res=0;
    REP(i,child[v].size()){
        int rec = DFS(child[v][i])+1;
        if(v!=0&&rec>=K)ans++,rec=0;
        res = max(res,rec);
    }
    return res;
}

int main(){

    cin>>N>>K;
    REP(i,N){
        int a;cin>>a;a--;
        if(i==0){
            if(a!=0)ans++;
            continue;
        }
        child[a].push_back(i);
    }

    DFS(0);

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 11904
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func x(a int) int {
	switch a % 4 {
	case 0:
		return a
	case 1:
		return 1
	case 2:
		return a + 1
	default:
		return 0
	}
}

func main() {
	A := nextInt()
	B := nextInt()
	T := nextInt()
	a := A
	ans := 0
	for i := 0; i <= T; i++ {
		if a == i {
			ans += B
			a += A
		}
	}
	fmt.Println(ans)
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#define MAX 105
using namespace std;
int a,x,y;
bool vis1[MAX], vis2[MAX],vis3[MAX],vis4[MAX];
int main() {
	int W, H, N,ans=0,black=0;
	cin >> W >> H >> N;
	ans = W * H;//1左2右3下4上
	for (int i = 1; i <= N; i++) {
		cin >>x>>y>>a;
		switch (a) {
		case 1:
			vis1[x] = 1;
			break;
		case 2:
			vis2[x] = 1;
			break;
		case 3:
			vis3[y] = 1;
			break;
		case 4:
			vis4[y] = 1;
			break;
		}
	}
	int max1, max2, max3, max4;
	max1 = max3 = 0;
	max2 = max4 = 999999;
	for (int i = 1; i <= W; i++) {
		if (vis1[i])
			max1 = max(i, max1);		
		if (vis3[i])
			max3 = max(i, max3);		
	}
	for (int i = 1; i <= H; i++) {
		if (vis2[i])
			max2 = min(i, max2);
		if (vis4[i])
			max4 = min(i, max4);
	}
	int w = 0, h = 0;
	if (max1 >= max2) {
		w = W;
		ans = 0;
	}
	else {
		max2 = max(0, W - max2);
		w = max1 + max2;
	}
	if (max3 >= max4) {
		h = H;
		ans = 0;
	}
	else {
		max4 = max(0, H - max4);
		h = max3 + max4;
	}
	//cout << max1 << " " << max2 << " " << max3 << " " << max4 << endl;
	//cout << w <<" " << h << endl;
//	black = h*W +w*H  - (max1+max3)*(max2+max4);
	//ans -= black;
	ans = (W-w)*(H-h);
	//if (ans < 0) ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pl = pair<ll, ll>;
using Tl = tuple<ll, ll, ll>;

const ll INF = 1e15;
const ld eps = 1e-6;

int main(){
  ll N, W;
  cin >> N >> W;
  vector<ll> dp(W+1);
  ll ans = 0;
  for(int i=0;i<N;i++){
    ll w,v;
    cin >> w >> v;
    for(int from=W;from>=0;from--){
      if(from + w > W)
	continue;
      dp[from + w] = max(dp[from + w], dp[from] + v);
      ans = max(ans, dp[from + w]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int n;
  cin >> n;
  Vi a(0);
  int now=0,memo;
  rep(i,0,n){
    cin >> memo;
    if(memo==i+1) now++;
    else {
      a.pb(now);
      now=0;
    }
  }
  
  a.pb(now);
  
  int ans = 0;
  rep(i,0,a.size()){
    ans += (a[i]+1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = list(map(int, readline().split()))
pS = [readline().decode('utf-8').split() for _ in range(M)]
cnt_list = [0] * (N + 1)
ACed_list = [0] * (N + 1)

for p_, s in pS:
    p_ = int(p_)

    if s == 'AC':
        if ACed_list[p_] == 0:
            ACed_list[p_] = 1
    else:
        if ACed_list[p_] == 0:
            cnt_list[p_] += 1

for i in range(N + 1):
    if ACed_list[i] == 0:
        cnt_list[i] = 0

print(sum(ACed_list), sum(cnt_list))


Measured memory_bytes: 42596
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
    if (n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if (n%2 == 1) x *= 2;
    return x;
}

mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 3596
class UnionFindWithSize(object):
    """UnionFindTree based on union by size + path compression.
    """
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.size = [1]*size

    def find(self, x):
        if self.parent[x] == x:
            return x
        # path compression
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        # union by size
        if self.size[x] < self.size[y]:
            self.size[y] += self.size[x]
            self.parent[x] = y
        else:
            self.size[x] += self.size[y]
            self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def sizeofset(self, x):
        return self.size[self.find(x)]

if __name__ == "__main__":
    N, M = map(int,input().split())
    edges = []
    for _ in range(M):
        edges.append(tuple(map(lambda x:int(x)-1,input().split())))
    uf = UnionFindWithSize(N)
    anss = []
    cnt = N*(N-1)//2
    for i in range(M-1, -1, -1):
        anss.append(cnt)
        a,b = edges[i]
        if not uf.same(a,b):
            cnt -= uf.sizeofset(a)*uf.sizeofset(b)
            uf.unite(a,b)
    for x in reversed(anss):
        print(x)

Measured memory_bytes: 28212
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <cmath>
using namespace std;

#define N 3

int a[N];

int main() {
	int ans = 0;

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

	sort( a, a+N );

	for( int i = 0; i < N-1; i++ ) {
		ans += abs(a[i+1] - a[i]);
	}

	cout << ans << "\n";
 
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(a,b) ((a > b)?(a):(b))

int main()
{
    int x;
    scanf("%d", &x);
    int max = 0;
    int i,j;
    if(x==1) printf("1");
    else {
        for(i=2;i<=31;i++){
            for(j=2;j<=9;j++){
                if ((int)pow(i,j) <= x)
                max = max(max, (int)pow(i,j));
            }
        }
        printf("%d", max);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,z;
int a[100005],f[100005];
int main(){
	cin>>n>>m;
	f[1]=1;
	f[2]=2;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>a[i];
		f[a[i]]=-1;
	}
 	for(int i=2;i<=n;i++){
 		if(f[i-1]==-1&&f[i-2]==-1){
 			cout<<"0";
			return 0;
		 }
 		if(f[i]==-1){
 			continue;
		}
 		if(f[i-1]==-1){
 			f[i]=f[i-2]%1000000007;
		 }
		 else if(f[i-2]==-1){
		 	f[i]=f[i-1]%1000000007;
		 }
		 else f[i]=(f[i-1]+f[i-2])%1000000007;
	}
	cout<<f[n]%1000000007;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a; i<=b; ++i)

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
typedef vector<vector<int>> vv;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int n;
    cin >> n;
    cout << (n+1) /2;
    return 0;
}


Measured memory_bytes: 3656
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val isPrime = Array(n + 1, {true})
    for(i in 2..n) if(isPrime[i]) {
        for(j in (i * 2)..n step i) isPrime[j] = false
    }
    var divisorCount = 1L
    for(i in 2..n) if(isPrime[i]) {
        var factorCount = 1
        var power = i
        while(power <= n) {
            factorCount += n / power
            power *= i
        }
        divisorCount *= factorCount
        divisorCount %= 1000000007
    }
    println(divisorCount)
}


Measured memory_bytes: 31380
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0;
        int ans = 0;

        if(a >= b){
            for(int i = a;i > 0;i--){
                if(a%i == 0 && b%i == 0){
                    ans = i;
                    cnt++;
                    if(cnt == k)
                    break;
                }
            }
        }else{
            for(int i = b;i > 0;i--){
                if(a%i == 0 && b%i == 0){
                    ans = i;
                    cnt++;
                    if(cnt == k)
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int d, n; cin >> d >> n;
  int res;
  if (d == 0) {
    res = n;
    if (n == 100) res++;
  } else if (d == 1) {
    res = n * 100;
    if (n == 100) res += 100;
  } else {
    res = n * 10000;
    if (n == 100) res += 10000;
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<string.h>
#include<queue>
#include<ctype.h>
#include<map>
#include<string>
using namespace std;
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<=0&&b>=0){
            printf("Zero\n");
            return 0;
    }
    int c=b-a+1;
    if(c%2==0||a>0)printf("Positive\n");
    else printf("Negative\n");
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
using namespace std;
int main(){

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

  int k;
  cin >> k;

  bool hoge = true;
  int min = num[0];
  int max = num[0];

  for(int i = 0; i < 5; i++){
    if(min > num[i]) min = num[i];
    else if(max < num[i]) max = num[i];
  }
  
  if (max - min <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;

}


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

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

char input[70][70];
string dp[70][70];

int comp(string s,string t) {
  if(s.length() != t.length()) return (s.length() - t.length());
  rep(i,s.length()) if(s[i] != t[i]) return (s[i] - t[i]);
  return 0;
}

int main() {
  int w,h,n;
  while(cin>>w>>h, w|h) {
    string s,above,left;
    rep(i,h) {
      cin>>s;
      rep(j,w) {
	dp[i][j] = "";
	input[i][j] = s[j];
      }
    }

    rep(i,h) rep(j,w) {
      char c = input[i][j];
      if(!(c <= '9' && c >= '0')) continue;
      above = ((i > 0) ? dp[i-1][j] : "") + string(1,c);
      left = ((j > 0) ? dp[i][j-1] : "") + string(1,c);
      dp[i][j] = (comp(above,left) <= 0) ? left : above;
      if(dp[i][j][0] == '0') dp[i][j] = dp[i][j].substr(1);
    }

    string ans = "";
    rep(i,h) rep(j,w) if(comp(ans,dp[i][j]) < 0) ans = dp[i][j];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
string ans="mfmfmfmfmfmfm.fmf";
string interactive(ll v){
    if(ans[v]=='.')return "Vacant";
    if(ans[v]=='m')return "Male";
    return "Female";
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    puta(0);
    string s; cin>>s;
    if(s=="Vacant")return 0;

    vl f(n,-1);
    f[0]=s=="Male";

    // f[0]=1;

    ll l=0,r=n;
    while(r-l>1){
        ll mid=(l+r)/2;
        // puta(l,r,mid);
        puta(mid);
        string res; 
        cin>>res;
        // res=interactive(mid);
        f[mid]=res=="Male";
        if(res=="Vacant"){
            return 0;
        }else{
            ll sl=f[l], sr=f[r%n], sm=f[mid];
            // puta("l:",sl," r:",sr, "mid(",mid,"):",sm,"=>",(mid-l)%2 xor sl==sm);
            if((mid-l)%2 xor sl==sm){ //矛盾がない
                l = mid;
            }else{
                r = mid;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1620
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        long[] A = new long[N];
        string[] input = Console.ReadLine().Split(' ');
        for(long i = 0; i < N; i++)
        {
            A[i] = long.Parse(input[i]);
        }
        long left = A[N-1];
        long right = A[0];
        long ans = 0;

        long[] right_list = new long[N];
        for (long j = N - 1; j > 0; j--)
        {
            if (j == N - 1) right = A[j];
            else { right = Gcd(A[j], right); }
            right_list[j] = right;
        }
        for (long i = 0; i < N; i++)
        {
            if (i == 0) { }
            else if (i == 1) left=A[0];
            else { left = Gcd(A[i-1], left); }

            if(i<N-1)right = right_list[i + 1];
            else { right = A[0]; }
            long temp = Gcd(left, right);
            if (ans < temp) { ans = temp; }
        }
        Console.WriteLine(ans);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}

Measured memory_bytes: 26076
#include <iostream>
#include <set>

using namespace std;

int main(void) {
  set<int> s;
  int q, command, x;
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> command >> x;
    switch(command) {
      case 0:
        s.insert(x);
        cout << s.size() << endl;
        break;
      case 1:
        cout << s.count(x) << endl;
        break;
      case 2:
        s.erase(x);
        break;
      case 3:
        int l, r;
        l = x;
        set<int>::iterator st, tm, it;
        cin >> r;
        st = s.lower_bound(l);
        tm = s.upper_bound(r);
        for(it = st; it != tm; it++) {
          cout << *it << endl;
        }
        break;
    }  
  }
  

}


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

long long int k;

#define MAX 50

long long int ans[MAX];

int main(){
	scanf("%lld", &k);
	long long int rest = k / MAX;
	for (int i = 0; i < MAX; i++){
		ans[i] += rest*MAX;
		ans[i] -= rest*(MAX-1);
		ans[i] += 49;
	}
	k %= MAX;
	for (int i = 0; i < k; i++){
		ans[i] += MAX;
		for (int j = 0; j < MAX; j++){
			if (i != j){
				ans[j]--;
			}
		}
	}
	puts("50");
	for (int i = 0; i < MAX; i++){
		if (i)printf(" ");
		printf("%lld", ans[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    int temp = 0;
    int res = 0;
    rep(i,s.size()){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            ++temp;
        }
        else temp = 0;
        res = max(res, temp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 764
s = list(map(int, input()))

s1 = s[0] * 10 + s[1]
s2 = s[2] * 10 + s[3]

ans = 0
if (1 <= s1 <= 12 and 0 <= s2 <=99):
    ans += 1
if (1 <= s2 <= 12 and 0 <= s1 <=99):
    ans += 2

if (ans == 0):
    print("NA")
elif (ans == 1):
    print("MMYY")
elif (ans == 2):
    print("YYMM")
elif (ans == 3):
    print("AMBIGUOUS")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;


int main(void){
  int c[3][3];

  rep(i,3){
	rep(j,3){
	  cin >> c[i][j];
	}
  }

  bool flag = true;
  rep(i,3){
	if(!(c[i%3][0]-c[(i+1)%3][0] == c[i%3][1]-c[(i+1)%3][1] && c[i%3][1]-c[(i+1)%3][1] == c[i%3][2]-c[(i+1)%3][2])) flag = false;
	if(!(c[0][i%3]-c[0][(i+1)%3] == c[1][i%3]-c[1][(i+1)%3] && c[1][i%3]-c[1][(i+1)%3] == c[2][i%3]-c[2][(i+1)%3])) flag = false;
  }

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

}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"

using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

int main(void) {
	int n;
	int a;
	cin >> n >> a;
	int numFivHun = n / 500;
	if (n - numFivHun * 500 <= a) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;

class UnionFind{
public:

    vector<int> parent;
    vector<int> sizev;
    vector<int> rankv;

    UnionFind();

    UnionFind(int n){
        rep(i,n + 1){
            parent.pback(i);
            sizev.pback(1);
            rankv.pback(1);
        }
    }

    int find(int n){

        vector<int> updatev;

        while(n != parent[n]){
            updatev.pback(n);
            n = parent[n];
        }

        rep(i, updatev.size()){
            parent[updatev[i]] = n;
        }

        return n;

    }

    int size(int n){
        return sizev[find(n)];
    }

    void merge(int a, int b){

        a = find(a);
        b = find(b);

        if(rankv[a] < rankv[b]){
            parent[a] = b;
            sizev[a] = sizev[a] + sizev[b];
        }else{
            parent[b] = a;
            sizev[b] = sizev[b] + sizev[a];

            if(rankv[a] == rankv[b]){
                rankv[a]++;
            }
        }
    }

};

int main(){

    int n,m;
    cin >> n >> m;

    UnionFind uf(n);

    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;

        uf.merge(x,y);
    }

    map<int,int> count;

    for(int i = 1; i <= n; i++){
        count[uf.find(i)] = uf.size(i);
    }

    cout << count.size() << endl;

    
    return 0;
}

Measured memory_bytes: 6124
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            String line = scanner.nextLine();
            System.out.print(line.charAt(i));
        }
        System.out.print("\n");
    }
}


Measured memory_bytes: 23380
#include <stdio.h>

int a[14][14] = {};

void small(int x, int y)
{
	a[x+1][y+2]++;
	a[x+2][y+1]++;
	a[x+2][y+2]++;
	a[x+2][y+3]++;
	a[x+3][y+2]++;
}

void middle(int x, int y)
{
	a[x+1][y+1]++;
	a[x+1][y+2]++;
	a[x+1][y+3]++;
	a[x+2][y+1]++;
	a[x+2][y+2]++;
	a[x+2][y+3]++;
	a[x+3][y+1]++;
	a[x+3][y+2]++;
	a[x+3][y+3]++;
}

void large(int x, int y)
{
	a[x][y+2]++;
	a[x+1][y+1]++;
	a[x+1][y+2]++;
	a[x+1][y+3]++;
	a[x+2][y]++;
	a[x+2][y+1]++;
	a[x+2][y+2]++;
	a[x+2][y+3]++;
	a[x+2][y+4]++;
	a[x+3][y+1]++;
	a[x+3][y+2]++;
	a[x+3][y+3]++;
	a[x+4][y+2]++;
}

int main(void)
{
	int x, y, mode;
	int i, j;
	int count = 0;
	int max = a[2][2];
	
	while(scanf("%d,%d,%d", &x, &y, &mode) != EOF) {
		if(mode ==1) small(x, y);
		else if(mode == 2) middle(x, y);
		else if(mode == 3) large(x, y);
	}
	for(i = 2; i < 12; i++) {
		for(j = 2; j < 12; j++) {
			if(a[i][j] == 0) count++;
			else if(a[i][j] > max) {
				max = a[i][j];
			}
		}
	}
	printf("%d\n%d\n", count, max);
	
	
	
	return 0;
}


Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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


  string S ; cin >> S;
  rmsame(S);
  rep(i,S.size()){
    if(S[i] != ('a'+i)) {
      cout << (char)('a'+i) << endl;
      return 0;
    }
  }

  if(S.size() == 26) cout << "None"<< endl;
  else cout << (char)('a'+S.size()) << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  string s;
  cin >> s;

  int N = s.length();
  int start, end;
  for (int i = 0; i < N; i++){
    if (s[i] == 'A'){
      start = i;
      break;
    }
  }
  for (int i = N - 1; i >= 0; i--){
    if (s[i] == 'Z'){
      end = i;
      break;
    }
  }
  cout << end - start + 1 << endl;
}


Measured memory_bytes: 3732
#include <cassert>
#include <deque>
#include <functional>
#include <utility>

template <typename Key, typename T, class Compare = std::greater<Key>>
class _01Heap {
public:
	using key_type = Key;
	using mapped_type = T;
	using value_type = std::pair<key_type, mapped_type>;
	using reference = value_type &;
	using const_reference = const value_type &;
	using key_compare = Compare;
	using container_type = std::deque<value_type>;
	using size_type = typename container_type::size_type;
	class value_compare {
		friend class _01Heap;
		const key_compare comp;
		value_compare() : comp() {}

	public:
		constexpr bool operator()(const_reference x, const_reference y) const {
			return comp(x.first, y.first);
		}
	};

private:
	const value_compare comp;
	container_type dq;
	size_type size_;
public:
	_01Heap() : comp(), dq(), size_(0){}
	const_reference top() const {
		assert(size_);
		return dq.front();
	}
	void pop() {
		assert(size_);
		--size_;
		dq.pop_front();
	}
	void push(const_reference x) {
		if (!size_)
			dq.push_front(x);
		else {
			assert(!comp(x, dq.front()) || !comp(dq.back(), x));
			if (comp(x, dq.front())) {
				dq.push_back(x);
			}
			else
				dq.push_front(x);
		}
		++size_;
	}
	size_type size() const noexcept { return size_; }
	bool empty() const noexcept { return !size_; }
};


struct edge {
	int to;
	int cost;
};
#include<iostream>
#include<vector>
#include<limits>
#include<tuple>
int main(void) {
	int k;
	std::cin >> k;
	std::vector<std::vector<edge>> G(k);
	for (int i = 0;i < k;++i) {
		G[i].push_back({ i * 10 % k,0 });
		G[i].push_back({ (i + 1) % k,1 });
	}
	_01Heap<int, int> Q;
	static constexpr int INF = std::numeric_limits<int>::max();
	std::vector<int> d(k, INF);
	Q.push({ 1,1 });
	d[1] = 1;
	int v, c;
	while (!Q.empty()) {
		std::tie(c, v) = Q.top();Q.pop();
		if (d[v] < c) continue;
		for (const auto &e : G[v]) {
			if (c + e.cost < d[e.to]) {
				d[e.to] = c + e.cost;
				Q.push({ d[e.to],e.to });
			}
		}
	}
	std::cout << d[0] << std::endl;
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool vis[100005];
vector<ll> v2(1000005);
vector<ll> v1[100005];
ll dfs(ll &cnt,ll x)
{
	vis[x]=true;
	cnt++;
	for(ll i=0;i<v1[x].size();i++)
	{
		if(vis[v1[x][i]]==false)
		{
			dfs(cnt,v1[x][i]);
		}
			v2[x]=max(v2[x],v2[v1[x][i]]+1);
		
	}
	return cnt;
}
int main()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		v1[x].push_back(y);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ll cnt=0;
		if(vis[i]==false)
		{
			ll res=dfs(cnt,i);
			ans=max(ans,res);
		}
	}
	cout<<*max_element(v2.begin(),v2.end())<<"\n";
	return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    int n, ind;
    ll l;
    cin >> n >> l;
    bool res = false;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i < n - 1; i++) {
        if(a[i] + a[i + 1] >= l)res = true,ind = i;
    }
    if(!res) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    vector<int> va = {ind};
    for(int i = ind + 1; i < n - 1; i++)va.emplace_back(i);
    for(int i = ind - 1; i >= 0; i--)va.emplace_back(i);
    reverse(va.begin(), va.end());
    for(auto i : va)cout << i + 1 << endl;

}

Measured memory_bytes: 4724
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

long long s[100000];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }

    long long ans = 0;
    for(int C = 1; C < N - 1; C++){
        long long tmp_ans = 0;
        //cout << "C: " << C << endl;
        set <int> visited;
        for(int k = 0; k < N - 1; k++){
            //cout << "k: " << k << endl;
            //cout << C * k << " " << N - 1 - C * k << endl;
            if((long long) C * (long long) k >= (long long) N - 1 ||
             visited.find(C * k) != visited.end() || visited.find(N - 1 - C * k) != visited.end() ||
             C * k == N - 1 - C * k || (N - 1 - (k + 1) * C <= 0)){
                break;
            }
            visited.insert(C * k);
            visited.insert(N - 1 - C * k);
            tmp_ans = tmp_ans + s[C * k] + s[N - 1 - C * k];
            //cout << tmp_ans << endl;
            ans = max(ans, tmp_ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long int arr[n-1],sum=0,temp,a,i,j;
    for(a=0;a<n;a++)
    {
        cin>>arr[a];
    }

    for (i = 0; i < n-1; i++)
   {
       for (j = 0; j < n-i-1; j++)
           if (arr[j] > arr[j+1])
           {
               temp=arr[j];
               arr[j]=arr[j+1];
               arr[j+1]=temp;
           }
   }


    for(a=0;a<n;a++)
    {
        //cout<<arr[a]<<" ";
        sum=sum+arr[a];
    }
    cout<<arr[0]<<" "<<arr[n-1]<<" "<<sum<<endl;

    return 0;
}



Measured memory_bytes: 3168
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,T;
double dp[2001][2001]; //dp[??´???][?????°] = ?¢????
char buf[2001];

void func(){

	scanf("%s",buf);
	for(int i = 0; i < N; i++){
		if(buf[i] == 'R'){
			dp[i][0] = 1.0;
		}else{
			dp[i][0] = 0.0;
		}
	}

	for(int count = 1; count <= T; count++){
		for(int loc = 0; loc < N; loc++){
			dp[loc][count] = 0;
			for(int i = 1; i <= 6; i++){
				dp[loc][count] += (dp[(loc+i)%N][count-1])/6.0;
			}
		}
	}

	double ans = 0.0;
	for(int loc = 0; loc < N; loc++){
		ans = max(ans,dp[loc][T]);
	}

	printf("%.10lf\n",ans);

}

int main(){

	while(true){
		scanf("%d %d",&N,&T);
		if(N == 0 && T == 0)break;

		func();
	}

	return 0;
}

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

int main()
{
    string a , b, c;
    cin>>a >>  b>> c;
    b[0]=b[0]-32 ;
    c[0]=c[0]-32;
    a[0]=a[0]-32 ;
    cout<< a[0] <<b[0]<<c[0];

	return 0;
}


Measured memory_bytes: 256
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;



#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 5e5 + 120;
 
int n ,res;

int main(){FAST;    
    cin >> n;
  cout <<   (n & 1 ? n * 2 : n);
}
 










Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int[] x;
    private static int[] y;

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            x = new int[N];
            y = new int[N];
            for (int i = 0; i < N; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
            }

            double[] sum = new double[1];
            int[] count = new int[1];
            dfs(0, N, new boolean[N], new int[N], sum, count);

            System.out.println(sum[0] / count[0]);
        }
    }

    private static void dfs(int index, int N, boolean[] used, int[] number, double[] sum, int[] count) {
        if (index >= N) {
            sum[0] += calculateLength(number);
            count[0]++;
            return;
        }

        for (int n = 0; n < N; n++) {
            if (used[n]) {
                continue;
            }
            used[n] = true;
            number[index] = n;
            dfs(index + 1, N, used, number, sum, count);
            used[n] = !true;
        }
    }

    private static double calculateLength(int[] number) {
        double l = 0;
        for (int i = 1; i < number.length; i++) {
            l += distance(number[i - 1], number[i]);
        }
        return l;
    }

    private static double distance(int i, int j) {
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return Math.sqrt(dx * dx + dy * dy);
    }
}


Measured memory_bytes: 27972
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;
#define a s[i]
#define b s[i+1]
#define c s[i+2]
#define d s[i+3]
#define e s[i+4]

int main()
{
	string s;
	getline(cin, s);
	while (s.find("apple", 0) != -1)
	{
		s.replace(s.find("apple", 0), 5, "*****");
	}
	while (s.find("peach", 0) != -1)
	{
		s.replace(s.find("peach", 0), 5, "apple");
	}
	while (s.find("*****", 0) != -1)
	{
		s.replace(s.find("*****", 0), 5, "peach");
	}
	cout << s << endl;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 202000, M = 1020000, inf = 0x3f3f3f3f;
int n,m,S,T,head[N],to[M],nxt[M],cap[M],edgenum=1;
Vi a[N],b[N];
void addedge(int u, int v, int c){
	to[++edgenum]=v;cap[edgenum]=c;
	nxt[edgenum]=head[u];head[u]=edgenum;
}
inline void add(int u, int v, int c){addedge(u,v,c);addedge(v,u,0);}
int q[N],dis[N],cur[N],match[N],ans[N];
inline bool bfs(){
	memset(dis,inf,4*(T+2));dis[T]=0;
	int f=0,r=1;q[f]=T;
	while(f!=r){
		int u=q[f++];
		L(i,u)if(cap[i^1]&&dis[to[i]]==inf){
			dis[to[i]]=dis[u]+1;q[r++]=to[i];if(to[i]==S)return 1;
		}
	}
	return 0;
}
inline int dfs(int u, int flow){
	if(u==T||!flow)return flow;
	int res=0;
	for(register int &i=cur[u];i;i=nxt[i])if(cap[i]&&dis[u]==dis[to[i]]+1){
		int tmp=dfs(to[i],min(flow,cap[i]));
		res+=tmp;flow-=tmp;cap[i]-=tmp;cap[i^1]+=tmp;if(!flow)break;
	}
	return res;
}
inline int dinic(){
	int res=0;
	while(bfs()){
		memcpy(cur,head,4*(T+2));res+=dfs(S,inf);
	}
	return res;
}
void GG(){puts("-1");exit(0);}
bool vis[N];
void solve(){
	vis[1]=1;int f=0,r=1;q[f]=1;
	while(f!=r){
		int u=q[f++];
		rep(t,0,SZ(b[u])-1)if(!vis[match[b[u][t]]]){
			ans[b[u][t]]=u;vis[match[b[u][t]]]=1;q[r++]=match[b[u][t]];
		}
	}
}
int main() {
	read(n);S=2*n+1;T=S+1;
	rep(i,1,n-1){
		add(S,n+i,1);
		int l;read(l);rep(j,1,l){
			int x;read(x);a[i].pb(x);if(x>1)add(n+i,x,1);
			b[x].pb(i);
		}
	}
	rep(i,2,n)add(i,T,1);if(dinic()!=n-1)GG();
	rep(u,1,n-1)L(i,n+u)if(!cap[i]&&to[i]>=2&&to[i]<=n)match[u]=to[i];
	solve();
	rep(i,1,n)if(!vis[i])GG();
	rep(i,1,n-1)printf("%d %d\n",match[i],ans[i]);
	return 0;
}


Measured memory_bytes: 32512
#include <stdio.h>

int main(){
  int coin,money,num;

  while(1){
    scanf("%d",&num);
    if(num==0) break;

    money=1000-num;
    coin=money/500;
    money%=500;
    coin+=money/100;
    money%=100;
    coin+=money/50;
    money%=50;
    coin+=money/10;
    money%=10;
    coin+=money/5;
    money%=5;
    coin+=money;

    printf("%d\n",coin);
  }

  return 0;

}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     	int t = Integer.parseInt(br.readLine());
     	//while(t-->0) {
     	int ar[] = new int[t];
   		int dp[] = new int[t];
   		StringTokenizer st = new StringTokenizer(br.readLine());
       	for(int i =0;i<t;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
     	
       	if(t==1)
       		System.out.println(ar[0]);
       	else {
       		dp[0] = 0;
       		for(int i =1;i<t; i++) {
       			dp[i] = Math.min(i>1 ? dp[i-2] + Math.abs(ar[i] - ar[i-2]) : Integer.MAX_VALUE, dp[i-1]+Math.abs(ar[i]-ar[i-1]));
       		}
       		System.out.println(dp[t-1]);
       	}
	}

}


Measured memory_bytes: 42512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,c,d,e,f,ansa,ansb;
  long double ans=-1;
  cin >> a >> b >> c >> d >> e >> f;
  vector<bool> water(f/100+1);
  vector<bool> sugar(1501);
  water[0]=true;
  sugar[0]=true;
  for(long i=1;i<f/100+1;i++) {
    if(i>=a) if(water[i-a]) water[i]=true;
    if(i>=b) if(water[i-b]) water[i]=true;
  }
  for(long i=1;i<1501;i++) {
    if(i>=c) if(sugar[i-c]) sugar[i]=true;
    if(i>=d) if(sugar[i-d]) sugar[i]=true;
  }
  for(long i=1;i<f/100+1;i++) {
    for(long j=0;j<1501;j++) {
      if(i*100+j>f) break;
      if((j+i-1)/i>e) break;
      if(water[i]&&sugar[j]) {
        if(j*1.0/i>ans) {
          ans=j*1.0/i;
          ansa=i*100+j;
          ansb=j;
        }
      }
    }
  }
  cout << ansa << " " << ansb << endl;
}

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

int main(){
    int n,ans = 1000000000,a = 0;
    cin >> n;
    vector<int>x(n);

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

    for(int j = 1; j <= 100 ;j++){
        a  = 0;
        for(int k = 0; k < n; k++){
            a += (x[k] - j) * (x[k] - j);
        }
        ans = min (ans,a);
    }
    cout << ans << endl;

      
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();	
		int [] L = new int [N+1];
		int [] R = new int [N+2];
		
		String color = sc.next(); 
		
		int left = 0;
		for (int i=0;i<N;i++) {
			if (color.charAt(i) == '#')
				left+=1;
			L[i+1]=left;
		}
		
		if (N!=1)
			L[N]=L[N-1];
		
		int right = 0;
		for (int i=N;i>0;i--) {
			if (color.charAt(i-1) == '.')
				right+=1;
			R[i]=right;
		}
		
		if (N!=1)
			R[0]=R[1];
		
		
		int tile = 100000;
		for (int i=1;i<N+1;i++)
			tile = Math.min(L[i-1]+R[i+1], tile);
		
		System.out.print(tile);
	}
}

Measured memory_bytes: 30096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			int l = sc.nextInt();
			
			int result = 0;
			Integer a[] = new Integer[n];
			for (int i = 0; i < n; i++) {
				a[i] = l + i;
				result += a[i];
			}
			
			int temp = Integer.MAX_VALUE;
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (Math.abs(a[i]) < temp) {
					temp = Math.abs(a[i]);
					ans = result - a[i];
				}
			}
			
			System.out.println(ans);
			

		}

	}
	
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <limits.h>
using namespace std;


				
int main()
{
	int n,m,a,b,co,ti,p,r;
	int money[100][100];
	int time[100][100];

	while(cin >> n >> m && n && m)
	{
		/*[m-1][m-1]ツづ慊づづ個配ツ療アツづーツ渉可甘コツ可サ*/
		for(int i=0;i<100;i++)
			for(int j=0;j<100;j++)
				time[i][j]=money[i][j]= (i-j) ? (1<<22) : 0;

		for(int i=0;i<n;i++)
		{
			cin >> a >> b >> co >> ti;
			money[a-1][b-1]=money[b-1][a-1]=co;
			time[a-1][b-1]=time[b-1][a-1]=ti;
		}
		/*ツδ渉ーツシツδδδ仰フツδ債イツドツ法 for time*/
		for(int k=0;k<m;k++)
			for(int i=0;i<m;i++)
				for(int j=0;j<m;j++)
					time[i][j]=time[j][i]=min(time[i][j],time[i][k]+time[k][j]);
					
		/*ツδ渉ーツシツδδδ仰フツδ債イツドツ法 for cost*/	
		for(int k=0;k<m;k++)
			for(int i=0;i<m;i++)
				for(int j=0;j<m;j++)
					money[i][j]=money[j][i]=min(money[i][j],money[i][k]+money[k][j]);
		cin >> p;
		
		/*
		for(int i=0;i<m;i++)
		{
			
			for(int j=0;j<m;j++)printf("%10d",money[i][j]);
			cout << endl;
		}
		*/
		
		for(int i=0;i<p;i++)
		{
			cin >> a >> b >> r;
			cout <<(r?time[a-1][b-1]:money[a-1][b-1])<< endl;
		}
	}
}
			
	

Measured memory_bytes: 944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int n;
int x[1000], y[1000];

int main() {
	int i;
	vector<int> p;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i] >> y[i];
	
	for (i = 0; i < n; i++) p.push_back(i);
	
	double ans = 0;
	int cnt = 0;
	do {
		double dist = 0;
		for (i = 0; i + 1 < n; i++) {
			double dx = abs(x[p[i + 1]] - x[p[i]]);
			double dy = abs(y[p[i + 1]] - y[p[i]]);
			dist += sqrt(dx * dx + dy * dy);
		}
		ans += dist;
		cnt++;
	} while (next_permutation(p.begin(), p.end()));
	ans /= cnt;
	
	printf("%.14f\n", ans);
	return 0;
}

Measured memory_bytes: 256
require 'set'

n, m, point = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| 
  a, b, c = line.strip.split.map(&:to_i)
  [a, b, -(c-point)]
}

graph = Array.new(n+1) { [] }
reverse_graph = Array.new(n+1) { [] }
edges = []

abc.each do |a, b, c|
  edges << [a, b, c]
  graph[a] << [b, c]
  reverse_graph[b] << [a, c]
end

def reachable(graph, s)
  visit = Set.new
  visit.add(s)
  q=[s]
  until q.empty?
    u=q.shift
    graph[u].each do |n, _|
      next if visit.include?(n)
      visit.add(n)
      q.push(n)
    end
  end
  visit
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
retrenched_nodes = reachable_from_s & reachable_to_g

edges = edges.select {|from, to,  _| retrenched_nodes.include?(from) && retrenched_nodes.include?(to) }

INF = 1 << 60
dist = Array.new(n+1, INF)
dist[1]=0
c=0

loop do
  updated = false
  edges.each do |from, to, cost|
    if dist[from] != INF && dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated=true
    end
  end
  break unless updated
  c+=1
  if c==retrenched_nodes.size
    p -1
    exit
  end
end

p [-dist[n], 0].max


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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

const int N = (int) 1e5 + 5;
const int inf = (int) 1e9 + 7;
const double pi=2* acos(0.0);
ll dp[102][N];
ll w[102],v[102];
ll n,W;
ll knapsnack(ll i,ll x)
{
    if(i>n)
        return 0;
    if(dp[i][x])
        return dp[i][x];
    ll p1=0,p2=0;

    if(x+w[i]<=W)
    {
        p1=v[i]+knapsnack(i+1,x+w[i]);
    }
    p2=knapsnack(i+1,x);
    //error(i,x,p1,p2)
    return dp[i][x]=max(p1,p2);
}
int main()
{

    n=inl(),W=inl();
    for(int i=1; i<=n; i++)
    {
        cin>>w[i]>>v[i];
    }
    ll res=knapsnack(1,0);

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








Measured memory_bytes: 77184