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

int main(){
    int n;
    while(cin >> n,n){
        
        // ?????????????????????????????±
        priority_queue<pii,vector<pii>,greater<pii>> pq;
        
        // ?????\??????????????????????´???????????????????
        map<int,vector<pii>> mp;
        
        // ??????????????????????????????->?????\??????
        map<int,int> endtoi;
        
        pq.push(make_pair(0, 1000000000));
        
        for(int i=0;i<n;i++){
            char c;cin >> c;
            if(c == 'W'){
                int i,s;
                cin >> i >> s;
                while(s > 0){
                    pii x = pq.top();
                    pq.pop();
                    if(s <= x.second - x.first){
                        pq.push(make_pair(x.first + s, x.second));
                        mp[i].push_back(make_pair(x.first, x.first + s - 1));
                        endtoi[x.first + s - 1] = i;
                        s = 0;
                    } else {
                        s -= x.second - x.first;
                        mp[i].push_back(make_pair(x.first, x.second - 1));
                        endtoi[x.second - 1] = i;
                    }
                }
            }
            if(c == 'D'){
                int i;
                cin >> i;
                for(int unsigned j = 0; j < mp[i].size(); j++){
                    pq.push(make_pair(mp[i][j].first,mp[i][j].second+1));
                    endtoi.erase(mp[i][j].second);
                }
                mp.erase(i);
            }
            // ?????°???
            if(c == 'R'){
                int p;
                cin >> p;
                auto it = endtoi.lower_bound(p);
                if(it == endtoi.end()){
                    cout << -1 << endl;
                    continue;
                }
                int i = it->second;
                
                bool isInRange = false;
                for(int unsigned j = 0;j<mp[i].size();j++){
                	if(mp[i][j].first <= p && p <= mp[i][j].second){
                		isInRange = true;
                	}
                }
                if(isInRange){
                    cout << i << endl;
                } else {
                    cout << -1 << endl;
                }
            }
            if(c == 'X'){
                
            }
        }
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 3352
#include<stdio.h>
int main(void){
	setvbuf(stdout,NULL,_IONBF,0);

	int r,c,i,j;
	scanf("%d %d",&r,&c);
	int num[r + 1][c + 1];
	for(i = 0;i <= r;i++){
		for(j = 0;j <= c;j++){
			num[i][j] = 0;
		}
	}
	for(i = 0;i < r;i++){
		for(j = 0;j < c;j++){
			scanf("%d",&num[i][j]);
		}
	}
	for(i = 0;i < r;i++){
		for(j = 0;j < c;j++){
			num[i][c] += num[i][j];
		}
	}
	for(i = 0;i <= c;i++){
		for(j = 0;j < r;j++){
			num[r][i] += num[j][i];
		}
	}
	for(i = 0;i <= r;i++){
		for(j = 0;j < c;j++){
			printf("%d ",num[i][j]);
		}
		printf("%d\n",num[i][j]);
	}

	return 0;
}

Measured memory_bytes: 644
import math
N=int(input())
x = []
for i in range(N):
    x.append(list(map(int,input().split())))
all_route=math.factorial(N)
route_sum=0
for i in range(N):
    for j in range(i+1,N):
        route_sum+=math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)*((all_route*2)//N)
print(route_sum/all_route)

Measured memory_bytes: 9100
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main()
{
    ll n,k;
    cin >> n >> k;
    deque<ll> v;
    for(ll i = 0; i < n; i++){
        ll t;
        cin >> t;
        v.push_back(t);
    }
    
    ll ans = -LINF;
    //i個使う(k-i個捨てる)
    for(ll i = k; i >= k/2; i--){
        //j個を前から取る
        for(ll j = 0; j <= i; j++){
            deque<ll> td = v;
            vector<ll> temp;
            for(int front = 0; front < j; front++){
                if(td.empty()) break;
                temp.push_back(td.front());
                td.pop_front();
            }
            for(int back = 0; back < i - j; back++){
                if(td.empty()) break;
                temp.push_back(td.back());
                td.pop_back();
            }
            sort(temp.begin(), temp.end());
            ll tempans = 0;
            for(int num = 0; num < i; num++){
                if(num >= temp.size()) break;
                if(num < k - i && temp[num] < 0) continue;
                else{
                    tempans += temp[num];
                }
            }
            ans = max(ans, tempans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e10;

int main(){
    ll n;
    scanf("%lld", &n);

    ll days = n;
    vector<ll> dp(3);
    while(days--){
        vector<ll> new_dp(3, 0);
        vector<ll> v(3);
        for(int i = 0; i < 3; i++)
            scanf("%lld", &v[i]);
        
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(i != j){
                    new_dp[j] = max(new_dp[j], dp[i] + v[j]);
                }
            }
        }
        dp = new_dp;
    }
    
    printf("%lld", max({dp[0], dp[1], dp[2]}));
    
    return 0;
}

Measured memory_bytes: 3788
from random import randint


class RollingHash:
    def __init__(self, s):
        self.base = [7073, 7577, 5445, 2742, 6972, 7547, 2267, 286, 6396, 7147,
                     3307, 188, 266, 8253, 2818, 9527, 5110, 1207, 4633, 6196,
                     309, 2646, 7533, 85, 9870, 4730, 6862, 9213, 7456, 7098,
                     6805, 674, 5821, 4864, 8061, 1826, 2219, 459, 5937, 5667,
                     9033, 5552, 7263, 2402, 9809, 3701, 7048, 2874, 8350, 6006,
                     973, 3317, 2522, 5546, 1669, 1545, 7972, 4979, 9905, 173,
                     6812, 7715, 5006, 6068, 6340, 4989, 5510, 6380, 1200, 6739,
                     5527, 4000, 6519, 3448, 2933, 6048, 3133, 1667, 9086, 8368,
                     4914, 7142, 2770, 7752, 391, 7052, 5476, 3105, 8322, 3501,
                     7454, 3167, 8730, 9002, 4564, 138, 2197, 7238, 3411, 7433][randint(0, 99)]
        self.mod = 4611686018427387903
        self.size = len(s)
        self.string = s

        self.hash = self.make_hashtable(s)
        self.pow = self.make_powtable()

    def make_hashtable(self, _s):
        hashtable = [0] * (self.size + 1)
        for i in range(self.size):
            hashtable[i + 1] = (hashtable[i] * self.base + ord(_s[i])) % self.mod
        return hashtable

    def make_powtable(self):
        power = [1] * (self.size + 1)
        for i in range(self.size):
            power[i + 1] = (self.base * power[i]) % self.mod
        return power

    def get_hash(self, left, right):
        """get hash of s[left:right]"""
        return (self.hash[right] - self.hash[left] * self.pow[right - left]) % self.mod

    def contain(self, a):
        """return a in s"""
        m = len(a)
        if m > self.size:
            return False
        hashs = self.get_hash(0, m)
        hasha = 0
        for i in range(m):
            hasha = (hasha * self.base + ord(a[i])) % self.mod
        for i in range(self.size - m + 1):
            if hasha == hashs:
                return True
            hashs = self.get_hash(i, m + i)
        return hasha == hashs


from collections import defaultdict
# d = defaultdict(int)で0で初期化
# d = defaultdict(lambda: 100)で100で初期化
n, s = int(input()), input()
rh = RollingHash(s)


def check(m):
    d = defaultdict(lambda: 10000000)
    for i in range(n - m + 1):
        h = rh.get_hash(i, i + m)
        d[h] = min(d[h], i)
        # m以上離れていて2回目
        if i - d[h] >= m:
            return True
    return False


l, r = 0, n // 2 + 1
while l + 1 < r:
    mid = (l + r) // 2
    if check(mid):
        l = mid
    else:
        r = mid
print(l)


Measured memory_bytes: 10820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
#define endl "\n"
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;


ll int power(ll int x, ll int y, ll int p)  
{  
   ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

ll int modInverse(ll int a,ll int m) 
{ 
    ll int g = __gcd(a, m); 
   
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
        
       return      power(a, m-2, m); 
   
} 


int main()
{
  fastio();
ll int T;
T=1;

while(T--)
{
  ll int n;
  cin>>n;
  ll int cnt=1,ans=0;
  while(cnt<=n)
  {
    ll int x;
    cin>>x;
    if(x%2&&cnt%2)ans++;
    cnt++;
  }

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	ll n; cin>>n;
	vector<ll> a(n+1);
	fore(i,0,n+1) cin>>a[i];
	vector<ll> mx(n+2);
	for(int i=n;i>=0;i--) mx[i]=(mx[i+1]+a[i]);

	ll low=0,hig=1,ans=0;
	fore(i,0,n+1){
		if(a[i]<low||a[i]>hig)cout<<"-1\n",exit(0);
		ll rem=hig-a[i];
		
		rem=min(rem,mx[i+1]);
		ans+=a[i]+rem;
		//puedo poner entre [0,2*rem]
		hig=min(1000000000000000000ll,2*rem);
	}
	cout<<ans<<"\n";
}

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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int n;

int main(){
    int n;
	cin >> n;
	
	vector<long long> h(n);
	vector<long long> ans;
	if(n==1){
		cout << 0 << endl;
		return 0;
	}
	int count = 0;
	cin >> h[0];	
	for(int i = 0; i < n-1; i++){
		cin >> h[i+1];
		if(h[i] >= h[i+1]) count++;
		else{
			ans.push_back(count);
			count = 0;
		}
		
		if(i == n-2) ans.push_back(count);
	}
	
	cout << *max_element(ans.begin(),ans.end()) <<endl;
	
    
    return 0;	
}

Measured memory_bytes: 2168
#include <cstdio>
#include <cmath>
using namespace std;
int N,D,X[10][10],ans;
int main() {
    scanf("%d%d",&N,&D);
    for (int i = 0;i < N;i++) for (int j = 0;j < D;j++) scanf("%d",&X[i][j]);
    for (int i = 0;i < N;i++) for (int j = 0;j < i;j++) {
        int sum = 0; for (int k = 0;k < D;k++) sum+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
        int sq = (int)round(sqrt(sum));
        if (sq*sq == sum) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n, ac = 0, wa = 0, tle = 0, re = 0;
	char str[10];
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%s", str);
		if(str[0] == 'A'){
			ac++;
		}
		if(str[0] == 'W'){
			wa++;
		}
		if(str[0] == 'T'){
			tle++;
		}
		if(str[0] == 'R'){
			re++;
		}
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
	return 0;
}


Measured memory_bytes: 1704
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
#define f first
#define s second
int main()
{
	int x[5];
	for(int i=0;i<5;i++)
	cin>>x[i];
	for(int i=0;i<5;i++)
	if(x[i]==0)
	{cout<<i+1;break;}
   return 0;	
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }


const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
	bool can = true;
	DESC(A);
	ll sum = 0;
	REP(i, N) {
		sum += A[i];
	}
	double border = sum / (4.0*M);
	REP(i, M) {
		if (A[i] < border) can = false;
	}
	if (can) cout << YES << "\n";
	else cout << NO << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N;
    cin >> N;

    int X[N];
    REP(i, N){
      cin >> X[i];
    }

    int trk;  //体力
    int mintrk  = 1000001;
    REP(i, 100){
      trk = 0;
      REP(j, N){
        trk += (int)pow((double)(X[j]-(i+1)), 2.0);
      }
      if(trk < mintrk){
        mintrk = trk;
      }
    }

    cout << mintrk << "\n"; 

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 105
#define INF (1e9)

int s2i(string s){
  stringstream ss;
  int res;
  ss<<s;
  ss>>res;
  return res;
}


int a[MAX][MAX];
vector<int> vx,vy;
int H,W;
string str;

bool solve(int id){
  int y=vy[id],x=vx[id];
  int ch=0,cw=0,sh=0,sw=0;
  for(int i=0;i<H;i++){
    if(a[i][x]==INF)continue;
    ch++;
    sh+=a[i][x];
  }
  if(ch==H-1){
    a[y][x]=a[H][x]-sh;
    return true;
  }

  for(int i=0;i<W;i++){
    if(a[y][i]==INF)continue;
    cw++;
    sw+=a[y][i];
  }
  if(cw==W-1){
    a[y][x]=a[y][W]-sw;
    return true;
  }
  return false;
}

int main(){
  int Tc=0;
  while(1){
    
    cin>>H;
    if(H==0)break;
    if(Tc!=0)cout<<endl;
    Tc++;

    cin>>W;
    vx.clear();
    vy.clear();
    for(int i=0;i<=H;i++){
      for(int j=0;j<=W;j++){
        cin>>str;
        if(str=="?"){
          a[i][j]=INF;
          vy.push_back(i);
          vx.push_back(j);
        }else a[i][j]=s2i(str);
      }
    }
    bool update=true;
    while(update){
      update=false;
      for(int i=0;i<(int)vx.size();i++){
        if(a[vy[i]][vx[i]]==INF)
          update|=solve(i);
      }
    }
    vector<int> ans;
    for(int i=0;i<(int)vx.size();i++)
      if(a[vy[i]][vx[i]]!=INF)
        ans.push_back(a[vy[i]][vx[i]]);
    if(ans.size()!=vx.size())cout<<"NO"<<endl;
    else{
      for(int i=0;i<(int)ans.size();i++)cout<<ans[i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1296
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int [n];
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		long [] sum = new long[n+1];
		for (int i=0;i<n;i++) {
			sum[i+1]=sum[i]+a[i];
		}
		ArrayList<Long> list = new ArrayList<>();
		for (int i=0;i<n;i++) {
			for (int j=i+1;j<=n;j++) {
				list.add(sum[j]-sum[i]);
			}
		}
		
	//	System.out.println(list.size());
		
		int digit = 40;
		long ans = 0;
		while (digit >= 0) {
			int count = 0;
			long tmp = ans+(1L<<digit);
		//	System.out.println(ans+" "+digit+" "+tmp);
			for (long l : list) {
				if ((l & tmp) == tmp) {
					count++;
				}
			}
			if (count >= k) {
				ans = tmp;
			}
			digit--;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 52772
// Mehul Mathur randi hai
// Murali big ghey
// RisHiH is slave
// Anamaya is Sexy
// Arihanth is gay

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

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

    ll p1 = (s.length()-1)/2;
    ll p2 = (s.length()+3)/2 -1;

    string s1 = s.substr(0,p1);
    string s2 = s.substr(p2,s.length()-1);

    string srev,s1rev,s2rev;
    srev = s;
    s1rev = s1;
    s2rev = s2;
    reverse(srev.begin(),srev.end());
    reverse(s1rev.begin(),s1rev.end());
    reverse(s2rev.begin(),s2rev.end());

    bool f1,f2,f3;
    f1=f2=f3=false;

    if(!s.compare(srev))
        f1=true;
    if(!s1.compare(s1rev))
        f2=true;
    if(!s2.compare(s2rev))
        f3=true;
    
    //cerr<<s<<" "<<s1<<" "<<s2<<endl;
    if((f1&&f2)&&f3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll ans = 0;
  chmax(ans, (n+a-1)/a+4);
  chmax(ans, (n+b-1)/b+4);
  chmax(ans, (n+c-1)/c+4);
  chmax(ans, (n+d-1)/d+4);
  chmax(ans, (n+e-1)/e+4);
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>
#include <functional>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

int main() {
	int n;
	cin >> n;
	int dp[100005];
	rep(i, 100005) {
		dp[i] = 0;
	}
	int c[100005];
	rep(i, n) {
		cin >> c[i];
	}
	if (n == 2) {
		cout << c[1] - c[0] << endl;
		return 0;
	}
	For(i,1, n) {
		dp[i] = min(abs(c[i] - c[i - 1]) + dp[i-1], abs(c[i] - c[i - 2]) + dp[i-2]) ;
	}
	cout << dp[n - 1] << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mems(a,x) memset(a,x,sizeof(a))
#define first fi
#define second se
using namespace std;
typedef long long ll;
const int mod=998244353,MS=105,N=3005;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
ll qpow(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
ll qpow(ll a,ll n,ll mod){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b,ll mod){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
struct vec
{
    double x,y;
    vec(double x=0,double y=0):x(x),y(y){}
    vec operator+(const vec&o)const{ return vec(x+o.x,y+o.y);}
    vec operator-(const vec&o)const{ return vec(x-o.x,y-o.y);}
    double operator*(const vec&o)const{ return x*o.x+y*o.y;}
    double operator^(const vec&o)const{ return x*o.y-y*o.x;}
    vec operator/(const double&o)const{ return vec(x/o,y/o);}
    vec operator*(const double&o)const{ return vec(x*o,y*o);}
    void sc(){scanf("%lf%lf",&x,&y);}
    double len(){return sqrt(x*x+y*y);}
};
struct Mat
{
    ll a[MS][MS];
    int n,m;
    Mat(int n=0,int m=0):n(n),m(m) { mems(a,0);}
    Mat operator*(const Mat&B)const
    {
        Mat C(n,B.m);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=B.m;j++)
                for(int k=1;k<=m;k++)
                C.a[i][j]=(C.a[i][j]+a[i][k]*B.a[k][j])%mod;
        return C;
    }
};
int n,x,c[N][N];
ll dp[N][N<<1];
ll C(ll n,ll m)
{
    if(m==0||n==m) return 1;
    if(m==1) return n;
    if(c[n][m]) return c[n][m];
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
ll solve(int m)
{
    ll ans=0;
    for(int i=0;i<x;i++) (ans+=dp[m][i])%=mod;
    for(int i=x+1;i<=2*m;i+=2)
    {
        int t=max(0,m-(i-(x-1))),s=i-2*(m-t);
        if(t>=0&&s>=0)
            (ans+=dp[t][s])%=mod;
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&x);
    dp[0][0]=1;
    for(int i=0;i<n;i++)
        for(int j=i;j<=i*2;j++)
    {
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j+2]+=dp[i][j])%=mod;
    }
    ll ans=0;
    for(int i=0;i<=n;i++)
        ans=(ans+C(n,i)*solve(i))%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 174848
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <chrono>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

inline uint64_t div_with_ceil(uint64_t x, uint64_t y)
{
  return (x + (y - 1)) / y;
}

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  vector<uint64_t> A(N);
  cin >> A;

  auto query = [&](uint64_t L) {
    uint64_t sum = 0;
    N_TIMES(n, N) {
      sum += div_with_ceil(A[n], L) - 1;
    }
    return sum <= K;
  };

  uint64_t lo = 1, hi = 1e+18;
  while (hi - lo > 1) {
    uint64_t mid = (hi + lo) >> 1;
    if (query(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }

  cout << ((query(lo)) ? lo : hi) << endl;

  return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
         
    int main() {
        int A, B;
        cin >> A >> B;

        int result = -1;

        for (int i = 1; i < 1100; i++){
            if(int(i * 0.08) == A && int(i * 0.10) == B){
                result = i;
                break;
            }
        }

        cout << result << endl;

        }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    if (a == b)
    {
        cout << "EQUAL" << endl;
        return 0;
    }
    if (a.size() != b.size())
    {
        if (a.size() > b.size())
        {
            cout << "GREATER" << endl;
            return 0;
        }
        else
        {
            cout << "LESS" << endl;
            return 0;
        }
    }
    for (int i = 0; i < a.size(); i++)
    {
        if (a.at(i) > b.at(i))
        {
            cout << "GREATER" << endl;
            return 0;
        }
        else
        {
            cout << "LESS" << endl;
            return 0;
        }
    }
}

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

const int mod = 1e9 + 7;

int bit[maxn][maxn] = {};
char s[maxn];
int n;

void add(int x, int y, int v) {
    for(int i = y; i < maxn; i += i & (-i)) {
        bit[x][i] = (bit[x][i] + v) % mod;
    }
}

int ask(int x, int y) {
    int ret = 0;
    for(int i = y; i > 0; i -= i & (-i)) {
        ret = (ret + bit[x][i]) % mod;
    }
    return ret;
}

int ask(int x, int l, int r) {
    if(l > r) return 0;
    return (ask(x, r) - ask(x, l - 1) + mod) % mod;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> (char*)(s + 2);
    add(1, 1, 1);
    for(int i = 2; i <= n; i++) {
        if(s[i] == '>') {
            for(int j = 1; j <= n; j++) {
                add(i, j, ask(i - 1, j, i - 1));
            }
        }
        else {
            for(int j = 1; j <= n; j++) {
                add(i, j, ask(i - 1, 1, j - 1));
            }
        }
    }
    cout << ask(n, n) << '\n';
    return 0;
}


Measured memory_bytes: 74052
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
#define ll long long
ll f[N][3],x;char s;
int main (){
	int n;cin>>n;
	cin>>f[0][0];f[0][1]=f[0][2]=-1ll<<60;
	for (int i=1;i<n;i++){
		cin>>s>>x;
		if (s=='+'){
			f[i][0]=max(max(f[i-1][0],f[i-1][1]),f[i-1][2])+x;
			f[i][1]=max(f[i-1][1],f[i-1][2])-x;
			f[i][2]=f[i-1][2]+x;
		}else{
			f[i][0]=max(max(f[i-1][0],f[i-1][1]),f[i-1][2])-x;
			f[i][1]=max(max(f[i-1][1],f[i-1][2])+x,f[i-1][0]-x);
			f[i][1]=max(max(f[i-1][1],f[i-1][2])-x,f[i][1]);
			f[i][2]=max(max(f[i-1][2]-x,f[i-1][2]+x),f[i-1][1]+x);
		}
	}
	printf ("%lld",max(max(f[n-1][0],f[n-1][1]),f[n-1][2]));
	return 0;
}

Measured memory_bytes: 2688
#! /usr/bin/perl

use strict;

my $S = <STDIN>;
$S =~ s/^\s*(.*)\s*$/$1/;
my $count = substr($S, 2, length($S)-3) =~ s/C/c/g;

if (substr($S, 0, 1, "a") eq "A" && $count == 1 && $S =~ /^[a-z]*$/) {
    print "AC\n";
} else {
    print "WA\n";
}


Measured memory_bytes: 512
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=1

n,k=LI()
a=[]

for i in range(n):
    x,y=LI()
    a.append((x,y))

a.sort()

ans=inf

for lx in range(n):
    for rx in range(lx+1,n):
        for ly in range(n):
            for ry in range(ly+1,n):
                c=0
                x1,x2,y1,y2=a[lx][0],a[rx][0],a[ly][1],a[ry][1]
                if y1>y2:
                    y1,y2=y2,y1
                for i in range(lx,rx+1):
                    x,y=a[i]
                    if x1<=x<=x2 and y1<=y<=y2:
                        c+=1
                
#                show(c,(lx,rx),(ly,ry),(x1,x2,y1,y2))
                if c>=k:
                    ans=min(ans,(x2-x1)*(y2-y1))

print(ans)



Measured memory_bytes: 51288
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

int main() {
    class SEGTREE{
                ll n, dflt;
          		vector<ll> dat;
            public:
            	SEGTREE(unsigned long _n, ll _a) : dat(_n * 4, _a){
            	    n = 1;
            	    dflt = _a;
            	    while(n < _n) n *= 2;
                }
                void update(ll k, ll a){
                    k += n;
                    dat[k] = a;
                    while(k > 0){
                        k /= 2;
                        dat[k] = max(dat[k * 2], dat[k * 2 + 1]);
                    }
                }
                void init(vector<ll> &v){
            	    for(int i = 0; i < v.size(); ++i) dat[i + n] = v[i];
            	    for(int i = n - 1; i >= 1; --i) {
            	        dat[i] = max(dat[i * 2], dat[i * 2 + 1]);
            	    }
            	}
                ll Q(ll a, ll b){
            	    return query(a, b, 1, 0, n);
            	}
                ll query(ll a, ll b, ll k, ll l, ll r){
                    if(r <= a || b <= l) return dflt;
                    if(a <= l && r <= b) return dat[k];
                    ll vl = query(a, b, k * 2, l, (l + r) / 2);
                    ll vr = query(a, b, k * 2 + 1, (l + r) / 2, r);
                    return max(vl, vr);
                }
                //単項にアクセスする[]だが、書き換え厳禁
                //一応後でinitすれば書き換えてもよさそうだが…
                ll & operator [](int k) {return dat[k + n];}
        };
    cin>>N;
    SEGTREE seg(N, 0);
    vec od(N);
    rep(i,N) od[i] = i;
    seg.init(od);
    vector<P> xd(N);
    rep(i,N) cin>>xd[i].fi>>xd[i].se;
    sort(ALL(xd));
    vec x(N), d(N);
    rep(i,N){
        x[i] = xd[i].fi;
        d[i] = xd[i].se;
        //cout<<x[i]<<' '<<d[i]<<endl;
    }
    Rrep(i,N){
        auto ite = lower_bound(ALL(x), x[i] + d[i]);
        seg.update(i, seg.Q(i, ite - x.begin()));
    }
    vec num(N), sum(N);
    num[N - 1] = 1;
    sum[N - 1] = 2;
    Rrep(i,N - 1){
        num[i] = (seg[i] == N - 1) ? 1 : sum[seg[i] + 1];
        sum[i] = (sum[i + 1] + num[i])%MOD;
    }
    cout<<sum[0]<<endl;
}

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

using namespace std ;

int main ()
{
    string s ;
    cin >> s ;
    set < char > ans ;
    for ( auto i : s )
    {
        ans.insert(i);
    }
    ans.size() == 2  ? cout << "Yes" : cout << "No" ;
    return 0 ;
}


Measured memory_bytes: 256
/*s1190073  Rina Sato
  File name: prog4a.c
  This is a linear search program.
*/

#include <stdio.h>

int main(void){
  int S[10000],T[500];
  int i,j,n,q,s,count=0;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j = 0 ; j < q ; j++){
    scanf("%d",&T[j]);
  }
  
  for(j = 0 ; j < q ; j++){
    for(i = 0 ; i < n ; i++){
      if(S[i] == T[j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
int main(){
    int n;
    std::cin>>n;
    long long int a[3];
    long long int ans=1;
    for(int i=0;i<n;i++){
        std::cin>>a[0];
        long long int temp=a[0];
        a[1]=ans;
        do{
            a[2]=a[0]%a[1];
            a[0]=a[1];
            a[1]=a[2];
        }while(a[2]!=0);
        ans=ans/a[0]*temp;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
'use strict'

main()

function main (input) {
  readInput()
  .then(parseInput)
  .then(calc)
}

function calc (input) {
  let n = input[0][0]
  let m = input[0][1]
  let edges = new Array(m).fill(0).map(
    (_, i) => ({
      from: input[i + 1][0] - 1,
      to: input[i + 1][1] - 1,
      weight: input[i + 1][2] * -1 // 反転
    })
  )

  // Find loop
  let d = new Array(n).fill(0)
  for (let i = 0; i < n; i++) {
    for (let edge of edges) {
      let shouldUpdate = d[edge.to] > d[edge.from] + edge.weight
      if (shouldUpdate) {
        d[edge.to] = d[edge.from] + edge.weight
        let foundLoop = i === n - 1 && edge.to === n - 1
        if (foundLoop) {
          console.log('inf')
          return
        }
      }
    }
  }

  // Find answer
  d = new Array(n).fill(Infinity)
  d[0] = 0
  for (let i = 0; i < n; i++) {
    for (let edge of edges) {
      let shouldUpdate = d[edge.from] < Infinity && d[edge.to] > d[edge.from] + edge.weight
      if (shouldUpdate) {
        d[edge.to] = d[edge.from] + edge.weight
      }
    }
  }
  console.log(d[n - 1] * -1)
}

function parseInput (inputRaw) {
  let input = inputRaw.split('\n').map(row => row.split(' ').map(Number))
  return input
}

function readInput () {
  return new Promise((resolve) => {
    let inputArr = []
    process.stdin.resume()
    process.stdin.setEncoding('utf8')
    process.stdin.on('data', (chunk) => {
      inputArr.push(chunk)
    })
    process.stdin.on('end', () => {
      let input = inputArr.join('').trim()
      resolve(input)
    })
  })
}


Measured memory_bytes: 12680
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  lint a, b;
  cin >> a >> b;
  lint cnt  = 1;
  lint maxi = max(a, b);
  for (lint i = 2; i * i <= maxi; ++i) {
    bool flag = true;
    if ((a % i == 0) && (b % i == 0)) ++cnt;
    while (a % i == 0) a /= i;
    while (b % i == 0) b /= i;
  }
  if (a != 1 && b != 1 && a == b) ++cnt;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
/*author:anshumanc007
   created on:08/01/2019
            */
//EMBRACE THE STRUGGLE!!!
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
//typedef pair<long long int,long long int> pa;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;

long double dp[3000][3000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0,W,ans;
    //heads->pi
    cin>>n;
    long double P[n],ans1=0;
    for(i=0;i<n;i++)
    {
        cin>>P[i];
    }
    
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            dp[i][j]=0.00;
        }
    }
    dp[0][0]=1;
  for(i=1;i<=n;i++)
  {
      for(j=0;j<=i;j++)
      {
          if(j==0)
          {
              dp[i][j]=dp[i-1][j]*(1-P[i-1]);
          }
          else
          dp[i][j]=dp[i-1][j]*(1-P[i-1])+dp[i-1][j-1]*P[i-1];
      }
  }
    j=n/2;
    for(i=j+1;i<=n;i++)
    {
        ans1=ans1+dp[n][i];
    }
    cout<<setprecision(15);
    cout<<ans1<<endl;
    
}

Measured memory_bytes: 140928
resident = [[[0] * 10 for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
    b, f, r, v = map(int, input().split())
    resident[b - 1][f - 1][r - 1] += v
for b in range(4):
    for f in range(3):
        print(" " + " ".join(map(str, resident[b][f])))
    if b < 3:
        print("####################")



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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define MAX 1000000

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

using namespace std;

int xx,yy;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void combinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin >> xx >> yy;
    if((xx+yy) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll alpha = (2*xx - yy)/3;
    ll beta = (2*yy - xx)/3;
    combinit();
    ll ans = comb(alpha+beta,alpha);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 
ll dp[110][110000];
int main(){
  int n,W;
  cin>>n>>W;
  ll w[n],v[n];
  rep(i,n){
    cin>>w[i]>>v[i];
  }
  rep(i,n+1){
    rep(j,1010*n+1)dp[i][j]=INF;
  }
  dp[0][0]=0;
  rep(i,n){
    rep(j,1010*n){
      dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
      if(j>=v[i])dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i]);

    }
  }
  ll ans =0;
  rep(i,n*1010+1){
    if(dp[n][i]<=W)ans=max((ll)i,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 88192
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static long[][] dp;
    static PrintWriter pw = new PrintWriter(System.out);
    public static long f(int[] arr, int[] w, int n, int sum, int W) {
        if (n == arr.length)
            return 0;
        if (dp[n][sum] != -1)
            return dp[n][sum];
        if (w[n] + sum <= W) {
            return dp[n][sum] = Math.max(1l * arr[n] + f(arr, w, n + 1, sum + w[n], W), f(arr, w, n + 1, sum, W));
        }
        return dp[n][sum] = f(arr, w, n + 1, sum, W);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt();
        int[] arr = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            arr[i] = sc.nextInt();
        }
        dp = new long[105][100000 + 5];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[i].length; j++)
                dp[i][j] = -1;
        pw.println(f(arr, w, 0, 0, W));
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 127188
#include<stdio.h>

int n;
int c[505];
int s[505];
int f[505];
int t[505];

int sj(int i,int x)
{
    if(i==n-1) return x;
    if(x<=s[i+1]) return t[i+1];
    else
    {
        if(x%f[i+1]==0) return sj(i+1,x+c[i+1]);
        else return sj(i+1,x/f[i+1]*f[i+1]+f[i+1]+c[i+1]);
    }
}

int main()
{
    int i,j,k;
    while(scanf("%d",&n)!=-1)
    {
        for(i=1;i<=n-1;i++) scanf("%d%d%d",&c[i],&s[i],&f[i]);
        t[n-1]=s[n-1]+c[n-1];
        t[n]=0;
        for(i=n-2;i>=1;i--) t[i]=sj(i,s[i]+c[i]);
        for(i=1;i<=n-1;i++) printf("%d\n",t[i]);
        printf("0\n");
    }
}


Measured memory_bytes: 128
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        #元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        #元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret;




dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

num_query = int(input())
for loop in range(num_query):
    top_num,front_num = map(int,input().split())
    print("%d"%(dice.query(top_num, front_num)))






Measured memory_bytes: 6400
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main() {
	int n,m;cin >> n >> m;
	set<int> r;
	for (int i = 0; i < n; ++i) {
		int k; cin >> k;
		set<int> tm;
		for (int j = 0; j < k; ++j) {
			int a;
			cin >> a;
			tm.insert(a);
		}
		if (i == 0) r = tm;
		set<int> tr = r;
		r.clear();
		set_intersection(tm.begin(), tm.end(), tr.begin(), tr.end(), inserter(r, r.end()));	
	}
	cout << r.size() << endl;
	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  vector<int> V(N), C(N);
  REP(i,N) cin>>V[i];
  int ans = 0;
  REP(i,N) {
    cin>>C[i];
    ans	+= max(0, V[i]-C[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 305
using namespace std;
const int mod=1e9+7; 
int dp[2][N][N];
int n,m;
vector<pair<int,int> > L[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r,x;i<=m;i++){
		scanf("%d%d%d",&l,&r,&x);
		L[r].push_back(make_pair(x,l));
	}
	int now=0;
	dp[now][0][0]=1;
	for(int i=1;i<=n;i++){
		memset(dp[now^1],0,sizeof(dp[0]));
		for(int j=0;j<i;j++)
			for(int k=0;k<=j;k++){
				if(dp[now][j][k]==0) continue;
				bool fl=true;
				for(int l=0;l<L[i].size()&&fl;l++)
					if(L[i][l].first==1){
						fl&=j<L[i][l].second;
					}else if(L[i][l].first==2){
						fl&=j>=L[i][l].second&&k<L[i][l].second;
					}else{
						fl&=k>=L[i][l].second;
					}
				if(!fl) {dp[now][j][k]=0;continue;}
				(dp[now^1][j][k]+=dp[now][j][k])%=mod;
				(dp[now^1][i][k]+=dp[now][j][k])%=mod;
				if(j!=k) (dp[now^1][i][j]+=dp[now][j][k])%=mod;
			}
		now^=1;
	}
	now^=1;
	long long ans=dp[now][0][0]*3;
	for(int i=1;i<n;i++)
		for(int j=0;j<i;j++)
			ans+=dp[now][i][j]*6LL;
	cout<<ans%mod<<endl;
	return 0;
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;cin>>S;
    int N=S.size();
    int res=0;
    for(int i=0;i<N-1;i++){
        if(S[i]!=S[i+1])res+=1;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 512
N = int(input())
S = input()

r_list = []
lb = 0
rw = S.count(".")
r_list.append(lb + rw)
for i in range(N):
  if S[i] == "#":
    lb += 1
  else:
    rw -= 1
  r_list.append(lb + rw)
print(min(r_list))

Measured memory_bytes: 11368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s,t;cin >> s >> t;
	rep(i,n){
		cout << s.at(i) << t.at(i);
	}
	cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(2 * n);
	rep(i, 2 * n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, n) {
		ans += a[2 * i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n,k = map(int,input().split())
aa = list(map(int,input().split()))

c = Counter(aa)
ans = 0
if len(c) > k:  
  cc = c.most_common()[::-1]
  for i in range(len(cc)-k):
    ans += cc[i][1]

print(ans)

Measured memory_bytes: 39352