akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {


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

    int[] dp = new int[N+10];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0]=0;
    for (int i = 0; i < N; i++) {
      dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(h[i] - h[i+1]));
      dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(h[i] - h[i+2]));
    }

    System.out.println(dp[N-1]);


  }


}


Measured memory_bytes: 50784
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
ll dsum(ll v){
  ll res = 0;
  while(v!=0){
    res ++ ;
    v /= 10;
  }
  return res;
}
signed main(){
  init_io();
  ll n,ans=1e18;
  cin >> n;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ans = min(ans,max(dsum(i),dsum(n/i)));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c = sc.nextInt()
  val x = sc.nextInt() / 50
  var ans = 0
  for {
    i <- 0 to a
    j <- 0 to b
    k <- 0 to c
    if i * 10 + j * 2 + k == x
  } {
    ans += 1
  }
  println(ans)
}


Measured memory_bytes: 55360
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))

ans = 0
for i in range(n):
  _a1 = sum(a1[:i+1])
  _a2 = sum(a2[i:])
  ans = max(ans,_a1+_a2)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void){
  int i, N, K, X, Y, sum = 0;
  
  scanf("%d", &N);
  scanf("%d", &K);
  scanf("%d", &X);
  scanf("%d", &Y);
  
  for(i = 1; i <= N; i++){
    if(i <= K){
      sum = sum + X;
    }else{
      sum = sum + Y;
    }
  }
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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(){
    vec a(4);
    cinf(4,a);
    sort(all(a));
    bool ok=1;
    if(a[0]!=1)ok=0;
    if(a[1]!=4)ok=0;
    if(a[2]!=7)ok=0;
    if(a[3]!=9)ok=0;
    cout<<(ok?"YES":"NO");
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final String input = stdin.nextLine();
	final StringBuilder sb = new StringBuilder();

	for ( final char ch : input.toCharArray() ) {
	    final char nch = ( char )( ( ch - 'A' - 3 + 26 ) % 26 + 'A' );
	    sb.append( nch );
	}
	System.out.println( sb.toString() );	
    }    
}

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

int main() {
    int N;
    cin >> N;
    double ans;
    for (int i=0; i<N; i++) {
        double x;
        cin >> x;
        ans += 1/x;
    }
    cout << fixed << setprecision(6);
    cout << 1/ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    const ll mod = 1e9+7;
    ll ans = 1;
    ll N; cin >> N;

    for(int i=1; i<=N; ++i){
        ans *= i;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import math

N = int(input())
D={}
T=list(map(int,input().split()))
if(T[0]!=0):
        print("0")
        exit()

for i in range(N):
    if D.get(T[i],None)==None:
        D[T[i]]=1
    else:
        D[T[i]]+=1

Max=max(D)
Min=min(D)
Len=len(D)
Item=sorted((D.items()))
if(Item[0][1]!=1):
        print("0")
        exit()
for i in range(Len):
    if(Item[i][0]!=i):
        print("0")
        exit()
ans=1
for i in range(1,Len):
    ans = (ans * (Item[i-1][1]**Item[i][1])) % 998244353
    
print(ans)

Measured memory_bytes: 21212
#include<bits/stdc++.h>
using namespace std;
int n;
double x, d, res;
int main()
{
	cin >> n >> x >> d;
	n *= 2;
	while (n)
	{
		res += (2 * x + (n - 1) * d) / 2;
		x = ((n + 2) * x + 5 * d) / n;
		d = (n + 4) * d / n;
		n -= 2;
	}
	printf("%.010lf\n", res);
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    var sc = Scanner(System.`in`)
    var N = sc.nextInt()
    var s = 2L
    var t = 1L
    for (i in 2..N) {
        val u = s + t
        s = t
        t = u
    }
    println(t)
}

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

int main(){
    int N, res=0;
    cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> H[i];
    }

    for(int i=0; i<N; i++){
        if((i>0 && H[i]-1<H[i-1]) || (i<N-1 && H[i+1]<H[i]-1)){
            if((i>0 && H[i]<H[i-1]) || (i<N-1 && H[i+1]<H[i])){
                res = 1;
            }
        }else{
            H[i]--;
        }

    }
    if(res==1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    if ((a == 5 && b == 5 && c ==7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, M);
  ll cnt = min(M / 2, N);
  M -= cnt * 2;
  print(cnt + M / 4);
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;

typedef pair<double,double> Pa;

int main()
{
	int n;
	
	for(int k = 1; k > 0; k++){
		cin >> n;
		if(n == 0){
			break;
		}
		Pa pr[51];
		for(int i = 0; i < n; i++){
			cin >> pr[i].first >> pr[i].second;
		}
		pr[n] = pr[0];
		double s = 0;
		
		for(int i = 0; i < n; i++){
			s += ((pr[i].first+pr[i+1].first)*(pr[i].second-pr[i+1].second))/2.0;
		}
		
		printf("%d %.1f\n", k, s);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
const int MAX = 100,INF = 1000000;
int edge[MAX + 1][MAX + 1][2],node[MAX + 1];
bool check[MAX + 1];

int f(int a,int b,int c,int m){
	int t,x;
	for(int i = 0;i <= MAX;++i){
		check[i] = false;
		node[i] = INF;
	}
	node[a] = 0;
	while(!check[b]){
		x = INF;
		for(int i = 1;i <= m;++i){
			if(!check[i] && node[i] < x) {
				x = node[i];
				t = i;
			}
		}
		check[t] = true;
		for(int i = 0;i <= m;++i){
			if(node[i] > node[t] + edge[t][i][c]){
				node[i] = node[t] + edge[t][i][c];
			}
		} 
	}
	return node[b];
}
int main(){
	int n,m,a,b,c,d;
	while(cin >> n >> m,n){
		for(int i = 0;i <= MAX;++i){
			for(int j = 0;j <= MAX;++j){
				edge[i][j][0] = edge[j][i][0] = INF;
				edge[i][j][1] = edge[j][i][1] = INF;
			}
		}
		for(int i = 0;i < n;++i){
			cin >> a >> b >> c >> d;
			edge[a][b][0] = edge[b][a][0] = c;
			edge[a][b][1] = edge[b][a][1] = d;
		}
		cin >> n;
		for(int i = 0;i< n;++i){
			cin >> a >> b >> c;
			cout << f(a,b,c,m) << endl;
		}
	}
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,m;cin >> n>>m;
    vector<lint> x(m),d(m-1);
    REP(i, m) { cin >> x[i]; }
    lint ans=0;
    sort(ALL(x));

    if(n>=m){

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

    REP(i,m-1){
        d[i] = x[i + 1] - x[i];
        ans += d[i];
    }
    sort(ALL(d));
    REP(i,n-1){
        ans -= d[m - 2 - i];
    }


    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 1792
using System;

class Problem0007
{
    static void Main(string[] args)
    {
        string line = Console.ReadLine();
        int week = int.Parse(line);
        Console.WriteLine(GetDebt(week));
    }

    static int GetDebt(int week)
    {
        if (week == 0)
        {
            return 100000;
        }
        else
        {
            return (int)Math.Ceiling(GetDebt(week - 1) * 1.05 / 1000.0) * 1000;
        }
    }
}

Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

bool isprime(int n)
{
	for(int i = 2;i <= sqrt(n);++i)
		if(n % i == 0)
			return false;
	return true;
}
int main()
{
	int n;cin >> n;
	int res = 0;
	for(int i = 0;i < n;++i)
	{
		int x;cin >> x;
		if(isprime(x))
			++res;
	}
	cout << res << endl;
	return 0;
}


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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back

const int N = 100005;

void solve() {
	int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> n;
	int a[n][3];
	for (i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	int dp[n][3];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (i = 1; i < n; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 3; k++) {
				if (j == k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
	return ;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,m,a,ans=0;
    cin>>n>>m;
    priority_queue<ll> q;
    rep(i,n){
        cin>>a;
        q.push(a);
    }
    rep(i,m){
        ll mx=q.top();
        q.pop();
        mx/=2;
        q.push(mx);
    }
    rep(i,n){
        ll x=q.top();
        q.pop();
        ans+=x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	vector<int> n(16);
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < 16; i++)
	{
		n[i] = 0;
		if (i % 2 == 0)
		{
			if(a > 0){
				a--;
			}
		}
		else
		{
			if (b > 0) {
				b--;
			}
		}
	}

	if (a > 0 || b > 0) cout << ":(";
	else cout << "Yay!";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <utility>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int,int> pii;
#define F first
#define S second

const int N = 56;

int a[N][N];
int dp[N][N];

int main ()
{
    int n,m;
    cin >> n >> m;
    memset(a,-1,sizeof(a));
    int _=0;
    for (int i=1;n>=i;i++)
    {
        string s;
        cin >>s;
        for (int j=1;m>=j;j++)
        {
            if (s[j-1] == '.') a[i][j] = 0;
            else _++;
        }
    }
    memset(dp,-1,sizeof(dp));
    dp[1][1] = 0;
    queue<pii> que;
    que.push(make_pair(1,1));
    while (!que.empty())
    {
        pii p=que.front();
        que.pop();
        int x=p.first;
        int y=p.second;
        int dx[4] = {0,1,0,-1},dy[4]={1,0,-1,0};
        for (int i=0;4>i;i++)
        {
            int tx=x+dx[i],ty=y+dy[i];
            if (a[tx][ty] != -1 && dp[tx][ty] == -1)
            {
                dp[tx][ty] = dp[x][y] + 1;
                que.push(make_pair(tx,ty));
            }
        }
    }
    if (dp[n][m] == -1) cout << -1 << endl;
    else cout << n*m - dp[n][m] - _ -1<< endl;
}


Measured memory_bytes: 256
<?php 
  
 fscanf(STDIN,"%d %d %d",$A,$B,$C);
 
if($A == $B){
    echo $C;
    return;
}
 
if($B == $C){
    echo $A;
    return;
}
 
if($A == $C){
    echo $B;
    return;
}
 
?>

Measured memory_bytes: 4212
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int n;
int C[VMAX+1];

void CountingSort(unsigned short *A, unsigned short *B, int  k){
	int i, j;
	for(i=0; i<=k; i++) C[i] = 0;
	
	/* C[i] に i の出現数を記録する */
	for(j=1; j<=n; j++) C[A[j]]++;
	
	/* C[i] に i 以下の数の出現数を記録する*/
	for(i=1; i<=k; i++) C[i]=C[i]+C[i-1];
	
	for(j=n; j>0; j--){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main(){
  unsigned short *A, *B;
  int i, k=-1;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

	/* your code */
	for(i=1; i<=n; i++) scanf("%hd", &A[i]);
	for(i=1; i<=n; i++){
		if(k<A[i]) k=A[i];
	}
	CountingSort(A, B, k);
	
	for(i=1; i<n; i++) printf("%hu ", B[i]);
	printf("%hu\n", B[n]);

  return 0;
}


Measured memory_bytes: 9604
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if((A==B)and(B==C)and(A==C)){
    cout << "No" << endl;
  }
  else if((A!=B)and(B!=C)and(A!=C)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

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

using namespace std;

int main(void){
//string S;
int N;
cin >> N;

vector<int> P(N);

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

vector<int> PP;

PP.push_back(P[0]);
for(int i = 1; i < P.size(); i++){
  if(P[i] <= PP.back()){
    PP.push_back(P[i]);
  }
}
cout << PP.size() << endl;

return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC054C - One-stroke Path
  // 自己ループと二重辺を含まないN頂点、M辺の重みなし無向グラフ
  // 全ての頂点を1度だけ訪ねるパスは何通りあるか
  // 解法2：next_permutation
  // N!通りの全探索を行う。1をスタート地点として、2～Nまでの各順列に対してその順番に辺が存在するかどうかを判定
  // 最後まで行けたらansをインクリメント
  int N, M; cin >> N >> M;
  vector<vector<bool> > G(N+1, vector<bool>(N+1, false));
  REP(i, M){
    int a, b; cin >> a >> b;
    G[a][b] = true; G[b][a] = true;
  }
  
  // next_permutationで使用する順列データを準備する
  // 1は固定なので、2からNまでの整数を準備
  vector<int> v(N);
  REP(i, N-1) v[i] = i + 2;

  int ans = 0;
  do{
    int from = 1; bool path = true; // スタート地点は1
    REP(i, N-1){ // permutaiton分だけループ
      int to = v[i];
      if(G[from][to]){
        from = to; // pathがあれば、toをfromにセット
      }else{
        path = false; break; // pathがなければpath=falseにしてbreak
      }
    }
    if(path) ans++; // path=trueならansをインクリメント
  }while(next_permutation(v.begin(), v.end())); 
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	static long ans[];
	static long sum[];
	static int n;
	static ArrayList<Integer>[] edges;
	static boolean[] used;
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	   	n = sc.nextInt();
	   	int q = sc.nextInt();
	   	sum = new long[n];
	   	edges = new ArrayList[n];
	   	ans = new long[n];
	   	used = new boolean[n];
	   	for(int i = 0; i < n; i++) {
	   		edges[i] = new ArrayList<>();
	   	}
	   	for(int i = 0; i < n-1; i++) {
	   		int a = sc.nextInt()-1;
	   		int b = sc.nextInt()-1;
	   		edges[a].add(b);
	   		edges[b].add(a);
	   	}
	   	for(int i = 0; i < q; i++) {
	   		int p = sc.nextInt();
	   		long x = sc.nextLong();
	   		sum[p-1]=sum[p-1]+x;
	   	}
	   	dfs(0,0);
	  	StringBuilder s = new StringBuilder();
	  	for(int i = 0; i < n; ++i) {
	  		s.append(ans[i]+" ");
	  	}
	  	System.out.println(s.toString());
	}
	 private static void dfs(int i, long j) {
		 if(used[i]) {
			 return;
		 }
		 used[i] = true;
		 ans[i] += sum[i]+j;
		 for(int next : edges[i]) {
			 dfs(next,ans[i]);
		 }
	 }
}

Measured memory_bytes: 237136
#include <iostream>
#include <string>

int main()
{
    std::string s,t;
    std::cin >> s >> t;
    
    int a = 0;
    int b = 0;
    std::cin >> a >> b;
    
    std::string u;
    std::cin >> u;
    
    if(u == s)
    {
        --a;
    }
    else
    {
        --b;
    }
    
    std::cout << a << ' ' << b << std::endl;
}

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

int main() {
  char c;
  cin>>c;
  
  if((c=='a')||(c=='i')||(c=='u')||(c=='e')||(c=='o')){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
    
  
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


int main()
{
int mn=INT_MAX,mx = 0;
int n;
cin>>n;

for(int index = 0 ;index <n ;index++)
{
    int c;
    cin>>c;

    mn=min(c,mn);
    mx = max(c,mx);
}

cout<<mx-mn<<endl;
 return 0;
}


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

typedef long long ll;
static const int MOD = 1e9+7;

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    ll sum = 0;
    for(int i=0; i<N; i++){
        cin>>A[i];
        sum += A[i];
        sum %= MOD;
    }

    ll ans = 0;
    for(int i=0; i<N; i++){
        sum -= A[i];
        if(sum < 0) sum += MOD;
        ans += A[i] * sum;
        ans %= MOD;
    }

    cout<<ans<<endl;
}

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


int main() {
  int a, b;
  cin >> a >> b;
  int ans = 6 - (a+b);
  cout << ans <<  endl;
  return 0;
}

Measured memory_bytes: 256
def isCLKWISE(ph):
    if (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) >= 0 : return True
    return False
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33828
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int p[] = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i + 1) {
                if (i == n - 1) {
                    int t = p[i];
                    p[i] = p[i - 1];
                    p[i - 1] = t;
                } else {
                    int t = p[i];
                    p[i] = p[i + 1];
                    p[i + 1] = t;
                }
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 49292
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> l(n);
  for (int i = 0; i < n; ++i)
    std::cin >> l.at(i);

  int cnt = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      for (int k = j + 1; k < n; ++k) {
        int a = l.at(i);
        int b = l.at(j);
        int c = l.at(k);
        if (a != b && b != c && c != a) {
          std::vector<int> r = {a, b, c};
          std::sort(r.begin(), r.end());
          if (r.at(0) + r.at(1) > r.at(2)) {
            cnt++;
          }
        }
      }

  std::cout << cnt << std::endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int l,r,n,g,i,j,k,b[100000]={0};
	string a;
	cin>>n>>g>>a;
	for (i=1;i<a.size();i++){
		if (a[i]=='C'&&a[i-1]=='A'){
			b[i]=b[i-1]+1;
		}
		else {
			b[i]=b[i-1];
		}
	}
	for (i=0;i<g;i++){
		cin>>l>>r;
		cout<<b[r-1]-b[l-1]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1488
local a,b,n=io.read("n","n","n")
local answer=-10^20
for i=(n>b and b or n),1,-1 do
    local x=math.floor(a*i/b)-a*math.floor(i/b)
    if answer<x then
        answer=x
    else
        break
    end
end
print(answer)

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int P[N];
    for(int i = 0;i < N;i++){
        cin >> P[i];
    }
    int ans = 0;
    int minp = 1000000;
    for(int i = 0;i < N;i++){
        if(minp > P[i]){
            minp = P[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll = long long;

#define MAX_W ((ll)1e9)
#define MAX_N (100)
#define MAX_V (1000)
int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);

	int N, W;
	std::cin >> N >> W;
	std::vector<ll> val(N), wei(N), dp(MAX_V*MAX_N+10, (ll)1e15);
	for(int i=0; i<N; i++){
		std::cin >> wei[i] >> val[i];
	}

	ll ans = 0;
	dp[0] = 0;
	for(int i=0; i<N; i++){
		for(int v = 1e5; v >= val[i]; v--){
			dp[v] = std::min( dp[v], dp[v - val[i]] + wei[i] );
			if( dp[v] <= W )
				ans = std::max(ans, (ll) v );
		}
	}

	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
import sys
n, a, b, c, d = map(int,input().split())
s = input()
judgesharp = False
judgepass = False
threepoint = 0
count = 0
a -= 1
b -= 1
c -= 1
d -= 1
if c < d:
  for i in s:
    if count < a or count > d:
      pass
    elif i == "#":
      if judgesharp == True:
        print("No")
        sys.exit()
      else:
        judgesharp = True
    else:
      judgesharp = False
    count += 1
  print("Yes")
else:
  for i in s:
    if count < a or count > c:
      pass
    elif i == "#":
      threepoint = 0
      if judgesharp == True:
        print("No")
        sys.exit()
      else:
        judgesharp = True
    else:
      if b-1 <= count and count <= d+1:
        threepoint += 1
      judgesharp = False
    if threepoint == 3:
      judgepass = True
    count += 1
  if judgepass:
    print("Yes")
  else:
    print("No")

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

int main() {
  int N;
  cin >> N;
  
  int S1 = 0, S2 = 0;
  
  vector <int> A;
  A.resize(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  for(int i = 0; i < N - 1; i++){
    for(int j = 0; j < N - 1; j++){
      if(A[j] < A[j + 1]){
        int k = A[j];
        A[j] = A[j + 1];
        A[j + 1] = k;
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if(i % 2 == 0)
      S1 += A[i];
    else 
      S2 += A[i];
  }
  
  cout << S1 - S2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
    val cake = Array(h){ readLine()!!}

    val ans = Array(h){ IntArray(w) { 0 } }
    var num = 1
    var copy = 0
    repeat(h) { hIdx ->
        var berry = false

        repeat(w) { wIdx ->
            val c = cake[hIdx][wIdx]
            if (c == '#') {
                if (berry) num++
                berry = true
            }
            ans[hIdx][wIdx] = num
        }

        if (!berry) {
            copy++
        }  else {
            for (i in hIdx-copy until hIdx) {
                ans[i] = ans[hIdx]
            }
            copy = 0
            num++
        }
    }

    if (copy > 0) {
        for (i in h-copy until h) {
            ans[i] = ans[h-copy-1]
        }
    }

    ans.forEach { println(it.joinToString(separator = " "))}
}

Measured memory_bytes: 42376
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
 int key;
 struct node *next;
 struct node *prev;
};
typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	       if ( com[6] == 'F' ) deleteFirst();
	       else if ( com[6] == 'L' ) deleteLast();
        }
        else {
	         delete(key);
           nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while ( cur != nil && cur->key != key) {
    cur = cur->next;
    }
    return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  deleteNode(t);
}

void delete(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}



Measured memory_bytes: 36116
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, str s) {
	/*if (depth == n) {
		ans.push_back(s);
		return false;
	}
	for (int i = 0; i < n; i++) {
		if (dfs(depth + 1, s + dic.at(i))) {
			return true;
		}
	}*/
	return false;
}


int main() {
	bool a = 0, b = 0;
	rep(i, 3) {
		char tmp;
		cin >> tmp;
		if (tmp == 'A')
			a = 1;
		else
			b = 1;
	}

	cout << (a && b ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e6 + 5;
 
 
int32_t main()
{
  IOS;
  vector<string> S;
  vector<int> T;
  int n , t, sum=0, y=0;
  string s ,s1 ;
  cin >> n ;
  for(int i=0;i<n;i++){
    cin >> s >> t;;
    S.push_back(s);
    T.push_back(t);
  }
  cin >> s1;
  for(int i=0;i<n;i++){
    if(s1==S[i]){
    	y++;
    	break;
    }
    else
      y++;
  }
  for(int i=y;i<n;i++){
    sum=sum+T[i];
  }
  cout << sum;
}

Measured memory_bytes: 256
n = gets.chomp

ans = 0
if n[0] == 'R' && n[1] == "R" && n[2] == "R"
  ans = 3
elsif n[0] == 'S' && n[1] == "S" && n[2] == "S"
  ans = 0
elsif (n[0] == 'R' && n[1] == "R") || (n[1] == "R" && n[2] == "R")
  ans = 2
else
  ans = 1
end
p ans

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

#define ll long long int
#define ld long double
#define pb push_back

ll mod = 1000000007;

using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{
	return a.second < b.second;
}

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 int n;
	 cin>>n;
	 pair<int,int> pi[n];

	 for (int i = 0; i < n; ++i)
	 {
	 	cin>>pi[i].first>>pi[i].second;
	 }

	 sort(pi,pi+n,comp);

	 int time = 0;
	
	for (int i = 0; i < n; ++i)
	{
	 	//cout<<pi[i].first<<" "<<pi[i].second<<"\n";
	 	time += pi[i].first;
	 	if(time > pi[i].second)
	 	{
	 		cout<<"No";
	 		return 0;
	 	}
	}

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

Measured memory_bytes: 1792
# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

def L():
    return list(map(int, stdin.readline().split()))

def In():
    return map(int, stdin.readline().split())

def I():
    return int(stdin.readline())

P = 1000000007
l = I()
a = l/3
print('%.12f'%(a*a*a))


Measured memory_bytes: 3316
import copy
from collections import Counter

def make_table():
    dp = copy.deepcopy(C)

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp


N = 10
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(N)]

A = []
for _ in range(H):
    A.extend(list(map(int, input().split())))

cntA = Counter(A)

dp = make_table()

print(sum([dp[key][1] * cntA[key] if key != -1 else 0 for key in cntA]))

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vl x(n),y(m);
    cin>>x>>y;
    ll xs=0;
    REP(i,n-1){
        xs+=(x[i+1]-x[i])*(i+1)*(n-i-1);
        xs%=MOD;
    }
    dprint(xs);
    ll ys=0;
    REP(i,m-1){
        ys+=(y[i+1]-y[i])*(i+1)*(m-i-1);
        ys%=MOD;
    }
    dprint(ys);
    cout<<(xs*ys)%MOD<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define ff first
#define ss second 
#define pb push_back
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Craig ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015
#define vll vector<ll>

int main() 
{ 
    ll i,j=0,k=0;
    string s;
    cin>>s;
    for(char i:s)
    {
        if(i=='R')
        {
            k++;
        }
        else
        {
            if(k>j)j=k;
            k=0;
        }
    }
    if(k>j)j=k;
            k=0;
    cout<<j<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REPN(i,a,b) for(int i = a; i >= b; i--)
typedef long long ll;

using namespace std;

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if (s.length()<=k) {
    	cout<<s<<"\n";
    }
    else {
    	REP(i,0,k-1) cout<<s[i];
    	cout<<"...\n";
    }

	return 0;
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)(n); i++)
#define Loop1(i, n) for(int i = 1; i <= (int)(n); i++)
#define Loopr(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
bool inrange(int x, int t) { return x >= 0 && x < t; }
bool inrange(vi xs, int t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	int m; cin >> m;
	vi cnt(n, 1);
	vi enable(n, 0);
	enable[0] = 1;
	Loop(i, m) {
		int s, t; cin >> s >> t; s--; t--;
		if (enable[s]) {
			enable[t] = 1;
		}
		if (cnt[s] == 1) {
			enable[s] = 0;
		}
		cnt[s]--;
		cnt[t]++;
	}
	int ans = 0;
	Loop(i, n) {
		if (enable[i]) ans++;
	}
	cout << ans << endl;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int x, k, d;
  cin >> x >> k >> d;

  if (abs(x / d) <= k) {
    if ((k - (x / d)) % 2 == 0) {
      cout << abs(x % d) << '\n';
    } else {
      cout << (min(abs(x % d + d), abs(x % d - d))) << '\n';
    }
  } else {
    cout << (min(abs(x - k * d), abs(x + k * d))) << '\n';
  }
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,n;
    scanf("%d%d",&h,&n);
    int a[n],b[n];
    for(int i=0;i<n;i++)
        scanf("%d%d",&a[i],&b[i]);
    int dp[n+1][h+1];//i番目の魔法までみてjダメージ与えたときの最小使用魔力(H段目は撃破出来たときの値)
    for(int i=0;i<=n;i++){
        for(int j=0;j<=h;j++){
            dp[i][j]=1000000000;
        }
    }
    dp[0][0]=0;
    int x=1000000000;
    for(int i=0;i<n;i++){
        for(int j=0;j<h;j++){
            dp[i][min(j+a[i],h)]=min(dp[i][min(j+a[i],h)],dp[i][j]+b[i]);
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            dp[i+1][min(j+a[i+1],h)]=min(dp[i+1][min(j+a[i+1],h)],dp[i+1][j]+b[i+1]);
        }
        x=min(x,dp[i][h]);
    }
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 39424
# -*- coding: utf-8 -*-

i=0
A = []
while i < 3: 
    m = map(int, input().split())
    A.append(list(m))
    i+=1
#print(A)
n=int(input())

i=0
lst = []
while i < n: 
    b = int(input())
    lst.append(b)
    i+=1
#print(lst)
a= {}
for i in range(0,3):
    for j in range(0,3):
        if A[i][j] in lst:
            a[str(i)+str(j)] = 1
        else:
            a[str(i)+str(j)] = 0


if a["00"] + a["01"]+ a["02"] == 3 \
    or a["10"] + a["11"] + a["12"] == 3 \
    or a["20"] + a["21"] + a["22"] == 3 \
    or a["00"] + a["10"] + a["20"] == 3 \
    or a["01"] + a["11"] + a["21"] == 3 \
    or a["02"] + a["12"] + a["22"] == 3 \
    or a["00"] + a["11"] + a["22"] == 3  \
    or a["02"] + a["11"] + a["20"] == 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string L;
  std::cin >> L;

  ll N = L.size();
  std::vector<ll> va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    va[i] = L[i] - '0';
  }

  // 通り数 : [使用した桁数][未満確定したかどうか]
  std::vector< std::vector<ll> > dp(N+1, std::vector<ll>(2, 0LL));

  dp[0][0] = 1LL;  // 最初は空と空の組み合わせしかないので１通り
  dp[0][1] = 0LL;  // 最初は未満確定したものはない

  // 桁DP
  for (ll i = 1; i <= N; i++) {
    dp[i][1] = (dp[i-1][1] * 3) % MOD; // 未満確定しているなら (0,0) (0,1) (1,0) のどれを選んでも良い
    if (L[i-1] == '1') {
      dp[i][1] = (dp[i][1] + dp[i-1][0] * 1) % MOD; // (0,0) を選んだら未満確定
      dp[i][0] = (dp[i][0] + dp[i-1][0] * 2) % MOD; // (0,1) (1,0) を選んだら未満確定しない
    } else {
      dp[i][0] = (dp[i][0] + dp[i-1][0] * 1) % MOD; // (0,0) を選ぶしかないが未満確定できない
    }
  }

  ll ans = (dp[N][0] + dp[N][1]) % MOD;
  print(ans);
  return 0;
}


Measured memory_bytes: 6608
#include<bits/stdc++.h>
using namespace std;
const int M=2e3+5;
int que[M],order[M],tmp[M],now[M],tot,top,n,k,q;
void in()
{
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=n;++i)scanf("%d",&que[i]),order[i]=que[i];
}
void add(int le,int ri)
{
    tot=0;
    if(le>ri||ri-le+1<k)return;
    for(int i=le;i<=ri;++i)tmp[++tot]=que[i];
    sort(tmp+1,tmp+1+tot);
    for(int i=ri-le+2-k;i>=1;--i)now[++top]=tmp[i];
}
int test(int mn)
{
    int p=1;top=0;
    for(int i=1;i<=n;++i)if(que[i]<mn)add(p,i-1),p=i+1;
    if(top<q)return INT_MAX; 
    sort(now+1,now+1+top);
    return now[q]-mn;
}
void ac()
{
    int ans=INT_MAX;
    sort(order+1,order+1+n);que[++n]=-INT_MAX;
    for(int i=1;i<n;++i)ans=min(test(order[i]),ans);
    printf("%d",ans);
}
int main()
{
    in();ac();
    return 0;
}

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

int main() {
   char a,b,c;
   cin >> a >> b >> c;
   int count=0;
   if(a == '1')count++;
   if(b == '1')count++;
   if(c == '1')count++;
   cout << count;
   return 0;
}


Measured memory_bytes: 256