akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class point2d{
    public:
    double x,y;
    constexpr static double EPS = 0.0000000001;

    point2d() : x(0),y(0){}
    point2d(double a, double b) :x(a), y(b){}

    double add(double a, double b){
        if(std::abs(a+b) < EPS * (std::abs(a)+std::abs(b))) return 0;
        return a+b;
    }
    point2d operator+(point2d v){
        point2d a(add(x, v.x), add(y, v.y)); return a;
    }
    point2d operator-(point2d v){
        point2d a(add(x, -v.x), add(y, -v.y)); return a;
    }
    double operator*(point2d v){ //内積
        return add(x*v.x, y*v.y);
    }
    point2d operator*(double v){
        x *= v; y *= v; return (*this);
    }
    point2d operator/(double v){
        if(v==0) cout << "zero division!!!" << endl;
        x /= v; y /=v; return (*this);
    }
    void operator=(point2d v){
        x = v.x; y = v.y;
    }
    bool operator==(point2d v){
        return (x==v.x)&&(y==v.y);
    }

    double simeq(point2d v){
        return ((x-v.x)<EPS && (v.x-x)<EPS && (y-v.y)<EPS && (v.y-y)<EPS);
    }
    double norm() { return add(x*x, y*y); }  //距離^2
    double length() { return std::sqrt(add(x*x, y*y)); }  //距離
    double isZero(){ point2d zero; return (*this).simeq(zero); }
    double dot(point2d v){ return add(x*v.x, y*v.y); }   // 内積
    double cross(point2d v){ return add(x*v.y, -y*v.x); } // 外積
    double cosine(point2d v){
        if((*this).isZero() || v.isZero()) cout << "cannot calc cosine by zero!!!" << endl;
        double cos = (*this).dot(v) / (*this).length() / v.length();
        return cos;
    }
    double sine(point2d v){
        if((*this).isZero() || v.isZero()) cout << "cannot calc sine by zero!!!" << endl;
        double sin = (*this).cross(v) / (*this).length() / v.length();
        return sin;
    }
    bool parallel(point2d v, bool near=true){  // 平行
        double cross = (*this).cross(v);
        if(near)return cross<EPS && cross>-EPS;
        else return cross==0.0;
    }
    bool orthogonal(point2d v, bool near=true){ // 直交
        double dot = (*this).dot(v);
        if(near)return dot<EPS && dot>-EPS;
        else return dot==0.0;
    }
    int clockwise(point2d v){
        double dot = (*this).dot(v);
        double cross = (*this).cross(v);
        if(cross>0.0) return -1; // 反時計回り
        else if(cross<0.0) return 1; //時計回り
        else if(dot>0.0 && (*this).norm() < v.norm()) return 2; // 直線上、向き同じ
        else if(dot<0.0) return -2; // 直線上、逆向き
        else return 0; // 線分上
    }

    friend std::ostream& operator<<(std::ostream &stream, const point2d v){
        stream << std::fixed << std::setprecision(13) << std::showpoint << v.x << " " << v.y;
        return stream;
    }
};

int main(){
    double x1, y1, x2, y2;
    int q;
    cin >> x1 >> y1 >> x2 >> y2 >> q;
    point2d p1(x1,y1), p2(x2,y2);
    double x,y;
    REP(i,q){
        cin >> x >> y;
        point2d p(x,y);
        cout << ((p2-p1) * ((p-p1)*(p2-p1)) / ((p2-p1).length() * (p2-p1).length()) + p1) << endl;
    }
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
long long N;
int depth;
inline long long number1(int len)
{
	long long ret=0;
	long long cnt=9;
	for(int i=0;i<len;i++)
	{
		ret+=cnt;
		cnt*=10;
	}
	return ret;
}
long long dfs(int i,long long diff)
{
	if(i==depth/2)
	{
//		cout<<"YES"<<diff<<endl;
		if(!diff)
			return 1;
		return 0;
	}
	long long delta=number1(depth-i-i-1);
	if(diff<0)
	{
		long long tmp=abs(diff);
		long long unit=tmp%10;
//		cout<<(diff+delta*((10-unit)%10))<<endl;
		return dfs(i+1,(diff+delta*((10-unit)%10))/10ll)*(unit+(!unit)*10);
	}
	else
	{
		long long unit=diff%10;
//		cout<<(diff-delta*((10-unit)%10))<<endl;
		return dfs(i+1,(diff-delta*((10-unit)%10))/10ll)*(unit+(!unit)*10-(!i));
	}
}
long long Count(int len)
{
	depth=len;
	long long ret=dfs(0,N);
	if(len%2)
		ret*=10;
//	cout<<len<<" "<<ret<<endl;
	return ret;
}
int main()
{
	cin>>N;
	if(N%9)
	{
		puts("0");
		return 0;
	}
	long long Ans=0;
	for(int i=2;i<=18;i++)
		Ans+=Count(i);
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
  int n;
  cin>>n;
  VI p(n),q(n),o(n);
  rep(i,n) cin>>p[i];
  rep(i,n) cin>>q[i];

  iota(o.begin(),o.end(),1);
  /*rep(i,n){
      cout<<o[i]<<" "<<p[i]<<" "<<q[i]<<endl;
  }*/
   bool flp,flq;
   int cnt=0,pans=0,qans=0;
  do{
      cnt++;
      flp=1,flq=1;
      rep(i,n){
          if(p[i]!=o[i]) flp=0;
          if(q[i]!=o[i]) flq=0;
      }
      //cout<<flp<<flq<<endl;
      if(flp) pans=cnt;
        
      if(flq) qans=cnt;

  }while(next_permutation(o.begin(),o.end()));
  
  cout<<abs(pans-qans)<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;



int N, M;
int dp[5005][5005] = {};
int main() {
	cin >> N >> M;
	rep(i, M) {
		int a, b, x;
		cin >> a >> b >> x; 
		dp[a][b] = x+1;
	}

	for (int i = 2; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			dp[i][j] = max({dp[i][j], dp[i-1][j-1]-1, dp[i-1][j]-1});
		}
	}

	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			if (dp[i][j]) cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 69884
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    string s,t;
    cin >> s;
    t.resize(N);
    ll i,j;
    t[0]='S';
    t[1]='S';
    for(i=0;i<4;i++){
        if(i==0){t[0]='S';t[1]='S';}
        if(i==1){t[0]='S';t[1]='W';}
        if(i==2){t[0]='W';t[1]='S';}
        if(i==3){t[0]='W';t[1]='W';}
        for(j=1;j<N-1;j++){
            if((t[j]=='S'&&s[j]=='o')||(t[j]=='W'&&s[j]=='x'))t[j+1]=t[j-1];
            if((t[j]=='W'&&s[j]=='o')||(t[j]=='S'&&s[j]=='x'))t[j+1]=((t[j-1]=='S')?'W':'S');
        }
        ll flag1=0,flag2=0;
        if((t[N-1]=='S'&&s[N-1]=='o')||(t[N-1]=='W'&&s[N-1]=='x')){
            if(t[0]==t[N-2])flag1=1;
        }
        if((t[N-1]=='W'&&s[N-1]=='o')||(t[N-1]=='S'&&s[N-1]=='x')){
             if(t[0]!=t[N-2])flag1=1;
        }
        if((t[0]=='S'&&s[0]=='o')||(t[0]=='W'&&s[0]=='x')){
            if(t[N-1]==t[1])flag2=1;
        }
        if((t[0]=='W'&&s[0]=='o')||(t[0]=='S'&&s[0]=='x')){
             if(t[N-1]!=t[1])flag2=1;
        }
        if(flag1&&flag2){cout << t << endl;return 0;}
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 512
MOD = 10 ** 9 + 7

n = int(input())
a = [int(x) for x in input().split()]

sum = 0
for x in a:
    sum += x
    sum %= MOD

ans = 0
for i in range(n):
    sum -= a[i]
    if sum < 0:
        sum += MOD
    ans += a[i] * sum
    ans %= MOD

print(ans)

Measured memory_bytes: 31696
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a : i128,
        b: i128,
        c: i128,
        d: i128
    };

    if a >= 0 && c >= 0 {
        let b = b as u128;
        let d = d as u128;

        println!("{}", b * d);
    } else {
        let x1 = a * c;
        let x2 = a * d;
        let x3 = b * c;
        let x4 = b * d;

        let mut result = std::cmp::max(x1, x2);
        result = std::cmp::max(result, x3);
        result = std::cmp::max(result, x4);
        println!("{}", result);
    }
}


Measured memory_bytes: 2192
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
	for(int t = 1; t <= T; t++){
		int x;
		cin >> x;
		cout << ((x >= 30) ? "Yes\n" : "No\n");
	}
}



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

int main(){
  int n;
  double sum;
  cin >> n;
  vector<double> v(n);
  for(int i=0;i<n;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  for(int i=0;i<n-1;i++){
    double j = pow(2,i+1);
    sum += v.at(i)/j;
  }
  sum += v.at(n-1)/pow(2,n-1);
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <utility>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
 
struct Point{
    double x,y,z;
    Point(double x, double y, double z):x(x), y(y), z(z){}
    Point(){}
    Point &operator +=(const Point &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
    Point &operator -=(const Point &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
    Point &operator *=(const double &a){ x*=a; y*=a; z*=a; return *this; }
    Point operator +(const Point &a) const{ return Point(x+a.x, y+a.y, z+a.z); }
    Point operator -(const Point &a) const{ return Point(x-a.x, y-a.y, z-a.z); }
    Point operator *(const double &a) const{ return Point(a*x, a*y, a*z); }
    Point operator -() { return Point(-x, -y, -z); }
};
 
double dot(const Point &a, const Point &b){
    return a.x*b.x +a.y*b.y +a.z*b.z;
}
Point cross(const Point &a, const Point &b){
    return Point(a.y*b.z -a.z*b.y, a.z*b.x -a.x*b.z, a.x*b.y -a.y*b.x);
}
double abs(const Point &a){
    return sqrt(dot(a, a));
}
Point unit(const Point &a){
    return a *(1/abs(a));
}
bool operator ==(const Point &a, const Point &b){
    return abs(a-b) < EPS;
}

Point projectionLP3(Point p, Point q, Point c){
    double t = dot(unit(q-p), c-p);
    return p +unit(q-p) *t;
}
double distanceSP3(Point p, Point q, Point c){
    Point r = projectionLP3(p, q, c);
    if(dot(q-p, r-p) < 0) return abs(c-p);
    if(dot(p-q, r-q) < 0) return abs(c-q);
    return abs(c-r);
}

pair<Point, Point> calcpos(double t, double m){
    using P2d = complex<double>;
    double arg1 = m*PI/180 +t/2500000 *2*PI;
    P2d moon2d = P2d(380000, 0) *P2d(cos(arg1), sin(arg1));
    Point moon = Point(moon2d.real(), moon2d.imag(), 0);
    double arg2 = t/7200 *2*PI;
    P2d kaguya2d = P2d(0, 1900) *P2d(cos(arg2), sin(arg2));
    Point kaguya = moon + Point(kaguya2d.real(), 0, kaguya2d.imag());
    return make_pair(moon, kaguya);
}

int main(){
    cout << fixed << setprecision(3);
    double m,t;
    cin >> m >> t;
    t *= 60;
    double dt = 1e-1;
    double ans = 0;
    Point origin(0, 0, 0);
    for(double time=dt/2; time<t; time+=dt){
        pair<Point, Point> pos = calcpos(time, m);
        if(distanceSP3(origin, pos.second, pos.first) < 1800){
            ans += dt;
        }
    }
    cout << fixed << setprecision(3);
    cout << ans/60 << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = (1e15);
int main(){
  int N, W;
  cin >> N >> W;
  int M = (1e4) + 1;
  vector<long long> DP(M,INF);
  DP[0] = 0;
  for(int i = 0; i < N; ++i){
    int v, w;
    cin >> v >> w;
    vector<long long> DP_ = DP;
    for(int j = 0; j <= M; ++j){
      if(DP[j] + w <= W)
        DP_[j+v] = min(DP_[j+v], DP[j]+w);
    }
    DP = DP_;
  }
  for(int i = M-1; i >= 0; --i){
    if(DP[i] != INF){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3276
#[allow(unused_imports)]
use std::collections::HashSet;
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::cmp::min;

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

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];
    let mut masu:Vec<Vec<char>> = Vec::with_capacity(h);
    for _i in 0..h {
        let row = read::<String>().chars().collect::<Vec<char>>();
        masu.push(row);
    }


    let answer = solve(h, w, &masu);
    println!("{}", answer);
}

fn solve(h: usize, w:usize, masu: &Vec<Vec<char>>) -> usize {
    let mut max_val : usize = 0;
    // dp[i][j]: masu[i][j]にランプをおいた場合に照らすマスの数。
    //           masu[i][j]の場合は[0, 0]
    //           そうでなければ[<縦で照らすマス>, <横で照らすマス>]、但し自身のマスは含まない。
    let mut dp = vec![vec![vec![0; 2]; w]; h];

    for i in 0..h {
        for j in 0..w {
            if masu[i][j] == '#' {
                dp[i][j][0] = 0; 
                dp[i][j][1] = 0; 
            } else {
                // 縦
                if i == 0 || masu[i-1][j]=='#' {
                    let mut i1 = i+1;
                    while i1<h && masu[i1][j] != '#' {
                        i1 += 1;
                    }
                    dp[i][j][0] = i1 - i - 1;
                }  else {
                    dp[i][j][0] = dp[i-1][j][0];
                }

                // 横
                if j == 0 || masu[i][j-1] == '#' {
                    let mut j1 = j + 1;
                    while j1 < w && masu[i][j1] != '#' {
                        j1 += 1;
                    }
                    dp[i][j][1] = j1 - j - 1;
                } else {
                    dp[i][j][1] = dp[i][j-1][1];
                }
                
                let val = dp[i][j][0] + dp[i][j][1] + 1;
                max_val = max(max_val, val);
            }
            //println!("{}, {} -> {}, {}",i, j, dp[i][j][0], dp[i][j][1] );
        }
    }
    
    
    return max_val;
}


Measured memory_bytes: 190716
#include<bits/stdc++.h>
#include <sstream>
using namespace std;
/*double Convert(double radian)
{
    return(radian*(180/pi));
}*/
int main()
{
    long long int n,total,count=0,count1=0,count2=0;
    cin>>n;
    total=(n*(n+1))/2;
    for(int i=3;i<=n;i=i+3)
    {
        count=count+i;
    }
    for(int i=5;i<=n;i=i+5)
    {
        count1=count1+i;
    }
    for(int i=15;i<=n;i=i+15)
    {
        count2=count2+i;
    }
    cout<<total-count-count1+count2;


}






Measured memory_bytes: 3624
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] A = new int[3][3];
		for(int i=0; i<3; i++)
			for(int j=0; j<3; j++)
				A[i][j] = sc.nextInt();
		
		boolean[][] bingo = new boolean[3][3];
		int N = sc.nextInt();
		for(int k=0; k<N; k++) {
			int b = sc.nextInt();
			for(int i=0; i<3; i++)
				for(int j=0; j<3; j++)
					if(A[i][j]==b)
						bingo[i][j] = true;
		}
		
		boolean ok = false;
		for(int i=0; i<3; i++) {
			boolean line = true;
			for(int j=0; j<3; j++) {
				line &= bingo[i][j];
			}
			ok |= line;
		}
		for(int i=0; i<3; i++) {
			boolean line = true;
			for(int j=0; j<3; j++) {
				line &= bingo[j][i];
			}
			ok |= line;
		}
		{
			boolean line = true;
			for(int i=0; i<3; i++) {
				line &= bingo[i][i];
			}
			ok |= line;
		}
		{
			boolean line = true;
			for(int i=0; i<3; i++) {
				line &= bingo[i][2-i];
			}
			ok |= line;
		}
		System.out.println(ok ? "Yes" : "No");

		sc.close();
	}
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[10101], d[1010101];
i64 mod_pow(i64 x, i64 y, i64 mod){
	i64 res = 1;
	while(y > 0){
		if(y & 1) res = res * x % mod;
		x = x*x %mod;
		y >>= 1;
	}
	return res;
}
i64 extgcd(i64 a, i64 b, i64 &p, i64 &q){
	if(b == 0){
		p = 1;
		q = 0;
		return a;
	}
	i64 c = extgcd(b, a%b, q, p);
	q -= a/b * p;
	return c;
}
i64 modinv(i64 a, i64 m) {
    i64 x, y;
    extgcd(a, m, x, y);
    return mod(x, m);
}
i64 fract(i64 x, i64 y, i64 mod){
	return x*modinv(y, mod) % mod;
}
bool prime(i64 x){
	for(i64 i = 2; i*i <= x; i++){
		if(x%i == 0) return 0;
	}
	return 1;
}
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++){
		int A = a[i];
		for(int j = 2; j*j <= a[i]; j++){
			if(!prime(j)) continue;
			int cnt = 0;
			while(A%j == 0){
				A /= j;
				cnt++;
			}
			chmax(d[j], cnt);
		}
		chmax(d[A], 1);
	}
	
	i64 cnt = 1;
	for(i64 i = 2; i <= 1000000; i++){
		if(d[i]>0 && prime(i)){
			cnt *= mod_pow(i,d[i],INF);
			cnt %= INF;
		}
	}
	
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		ans += fract(cnt, a[i], INF);
		ans %= INF;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll x,y,z;
int main()
{
    //IOS;
    cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public int minCost(int[] height, int K) {

		int N = height.length;

		if(N<=1) return 0;

		int[] dp = new int[N];

		dp[0] = 0;
		dp[1] = Math.abs(height[1]-height[0]);

		for(int i=2; i<N; i++) {
			int min = Integer.MAX_VALUE;
			for(int j=K; j>=1; j--) {
				if(i-j>=0) {
					min = Math.min(min, dp[i-j]+Math.abs(height[i]-height[i-j]));
				}else {

				}
			}
			dp[i] = min;
		}
		return dp[N-1];
	}

	public static void main(String[] args) {

		
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

		Main obj = new Main();
		int result = obj.minCost(arr, K);
		System.out.println(result);
	}

}


Measured memory_bytes: 49020
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] order = new int[n];

    for (int i = 0; i < n; i++) {
      int student = sc.nextInt();
      order[student - 1] = i + 1;
    }

    for (int j = 0; j < order.length; j++) {
      System.out.print(order[j] + " ");
    }
  }
}


Measured memory_bytes: 63228
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    int N;
    cin >> N;
    vector<pair<double,double>>AB(N);
    for(int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(),AB.end());
    int X = 0,Y = 0;
    if(N%2 == 0) {
        X = AB[N/2-1].first+AB[N/2].first;
    }
    else {
        X = AB[N/2].first;
    }
    for(int i = 0; i < N; i++) {
        swap(AB[i].first,AB[i].second);
    }
    sort(AB.begin(),AB.end());
    if(N%2 == 0) {
        Y = AB[N/2-1].first+AB[N/2].first;
    }
    else {
        Y = AB[N/2].first;
    }
    cout << Y-X+1 << endl;
}


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

int main() {
  string N;
  cin >> N;
  if(N=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  if(N=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  if(N=="Rainy"){
    cout<<"Sunny"<<endl;
  }
}

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

using namespace std;

int main()
{
    long long int a, b;
    cin >> a >> b;

    int hcf = 1;
    for (int i=1; i<=min(a,b); i++) {
        if (a%i==0 && b%i==0) {
            hcf = i;
        }
    }

    cout << a*b/hcf << "\n";

    return 0;
}


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

#define MOD (1000000000+ 7)
#define MAX 200

int N, X;
int S[MAX];

long long dp[MAX + 1][100000 + 1];

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

	sort( S, S + N, greater<int>() );
	dp[0][X] = 1;
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j <= X; j++ ) {
			dp[i + 1][j] = dp[i][j] * (N - 1- i) % MOD;
			dp[i + 1][j % S[i]] += dp[i][j];
			dp[i + 1][j % S[i]] %= MOD;
		}
	}
	long long ans = 0;
	for( int j = 0; j <= X; j++ ) {
		ans += dp[N][j] * j % MOD;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 156544
#include<bits/stdc++.h>
using namespace std;
int main(){
    	char ch;

	while(1){
		scanf("%c",&ch);
		if(islower(ch)){
			ch = toupper(ch);
		}
		else if(isupper(ch)){
			ch = tolower(ch);
		}
		printf("%c",ch);

		if(ch == '\n') break;
	}
}


Measured memory_bytes: 3140
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int n;
int ret[100];
double xi,yi;
vector<double> x,y,len2;
const double far = 1e12;
const double pi3 = 3.141592653589793;
const int itr = 3*(1<<20);
int main(){
    I(n);
    REP(i,n){
        cin >> xi >> yi;
        x.pb(xi);
        y.pb(yi);
    }
    len2.resize(n);
    REP(i,itr){
        xi = sin(2*pi3*i/itr);
        yi = cos(2*pi3*i/itr);
        REP(j,n){
            len2[j] = xi*x[j]+yi*y[j];
        }
        ret[ distance(len2.begin(), min_element(len2.begin(),len2.end())) ]++;
    }
    REP(i,n) printf("%.7f\n",ret[i]/(double)itr);
}


Measured memory_bytes: 640
#include <cstdint>
#include <iostream>

using namespace std;

constexpr int kMOD = 1000000007;

int64_t pow(int m, int n) {
  if (n == 0) return 1;
  const int64_t r = pow((int64_t)m * m % kMOD, n / 2);
  if (n % 2 == 1) return r * m % kMOD;
  return r;
}

int main() {
  int m, n;
  cin >> m >> n;
  cout << pow(m, n) << endl;
  return 0;
}



Measured memory_bytes: 3076
object Main extends App {

  import scala.io.StdIn._


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val prefNum = Array.tabulate(n){it ⇒ 1000000000000L + (it + 1) * 1000000L}
  val id = Array.tabulate(m){_ ⇒ ""}
  val towns = Array.tabulate(m){_ ⇒
    val Array(p, y) = readLine.trim.split(' ').map(_.toInt)
    Town(p, y)
  }.zipWithIndex.sortBy(_._1.year)
  for ((town, i) ← towns){
    prefNum(town.pref - 1) += 1
    id(i) = prefNum(town.pref - 1).toString.takeRight(12)
  }
  for (i ← id){
    println(i)
  }
  case class Town(pref: Int, year: Int)
}


Measured memory_bytes: 85988
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    vector<char> S(4);
    REP(i, 4) cin >> S[i];
    int A = S[0]-48, B = S[1]-48, C = S[2]-48, D = S[3]-48;
    if (A+B+C+D == 7) {
        cout << A << "+" << B << "+" << C << "+" << D;
    } else if (A+B+C-D == 7) {
        cout << A << "+" << B << "+" << C << "-" << D;
    } else if (A+B-C+D == 7) {
        cout << A << "+" << B << "-" << C << "+" << D;
    } else if (A+B-C-D == 7) {
        cout << A << "+" << B << "-" << C << "-" << D;
    } else if (A-B+C+D == 7) {
        cout << A << "-" << B << "+" << C << "+" << D;
    } else if (A-B+C-D == 7) {
        cout << A << "-" << B << "+" << C << "-" << D;
    } else if (A-B-C+D == 7) {
        cout << A << "-" << B << "-" << C << "+" << D;
    } else if (A-B-C-D == 7) {
        cout << A << "-" << B << "-" << C << "-" << D;
    }
    cout << "=7" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  cout << 180 * (n - 2) << endl;
}


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

int main() 
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long suma=0;
	bool czy=false;
	int n,a,b,mn=INT_MAX;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		suma+=a;
		if(a>b)
		mn=min(mn,b);
		if(a!=b)czy=true;
	}
	if(czy==false)cout<<0;
	else cout<<suma-mn;
	
	return 0;
}

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

int main(){
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 3600 % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <utility>
#include <string>
#include <stack>
#include <cstdlib>

using namespace std;

int main(void)
{
    int temp1, temp2;
    stack<int> num;
    string buf;

    while (cin >> buf)
    {
        switch(buf[0])
        {
            case '+':
            temp1 = num.top();
            num.pop();
            temp2 = num.top();
            num.pop();
            num.push(temp2 + temp1);
            break;
            case '-':
            temp1 = num.top();
            num.pop();
            temp2 = num.top();
            num.pop();
            num.push(temp2 - temp1);
            break;
            case '*':
            temp1 = num.top();
            num.pop();
            temp2 = num.top();
            num.pop();
            num.push(temp2 * temp1);
            break;
            default:
            num.push(atoi(buf.c_str()));
            break;
        }
    }
    cout << num.top() << endl;
    return 0;
}


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif

    string str;
    cin >> str;
    int len = str.length();
    if(len % 2 == 0){
    	if(str[0] == str[len - 1]){
    		cout << "First" << endl;
    	}else{
    		cout << "Second" << endl;
    	}
    }else{
    	if(str[0] == str[len - 1]){
    		cout << "Second" << endl;
    	}else{
    		cout << "First" << endl;
    	}
    }



    return 0;
}




Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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


int main() {
    int N,M;
    cin >> N >> M;

    vector<int> A(M);
    vector<int> B(M);

    REP(i,M){
    	cin >> A[i] >> B[i];
    	--A[i];
    	--B[i];
    }

    UnionFind uf(N);
    vector<lint> fuben(M);

    fuben[M-1] = (lint)N*(N-1)/2;
	lint t=0;
    FOR(i,1,M){

    	if(!uf.issame(A[M-i],B[M-i])){
    		t+=uf.size(A[M-i])*uf.size(B[M-i]);
    	}
    	uf.merge(A[M-i],B[M-i]);

    	fuben[M-1-i] = (lint)N*(N-1)/2-t;



    }

    REP(i,M){
    	cout << fuben[i] << endl;
    }



    return 0;
}


Measured memory_bytes: 3328
S = input()
l = S[:2]
r = S[2:]
 
lcnt = 0
rcnt = 0
if 0 < int(l) <= 12:
    lcnt = 1
if  0 < int(r) <= 12:
    rcnt = 1
if lcnt and rcnt:
    print('AMBIGUOUS')
    exit()
elif lcnt:
    print('MMYY')
    exit()
elif rcnt:
    print('YYMM')
    exit()
else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
    ll n, k;
    cin >> n >> k;
    ll a[n + 1];
    for (int i = 1; i <= n; i++) cin >> a[i];
    deque<int> b;
    map<int, bool> used;
    int cur = 1;
    while (!used[cur]) {
        used[cur] = true;
        b.push_back(cur);
        cur = a[cur];
    }
    int idx = 0;
    for (int i = 0; i < b.size(); i++) {
        if (cur == b[i]) {
            idx = i;
            break;
        }
    }
    if (k <= idx) cout << b[k];
    else {
        k -= idx;
        for (int i = 0; i < idx; i++) b.pop_front();
        k %= (ll)b.size();
        cout << b[k];
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 15268
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);{
	if(a<b)
		printf("a < b");
	else if(a==b)
		printf("a == b");
	else
		printf("a > b");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int A, B, H, M;
    double theta_rad, ans;

    cin >> A >> B >> H >> M;

    // 針のなす角
    theta_rad = ((double)(60 * H + M) / (60 * 12) - (double)M / 60) * 2 * M_PI;

  	// cout << (double)(60 * H + M) / (60 * 12) * 360 << endl;
    // cout << (double)M / 60 * 360 << endl;

    ans = sqrt(A*A + B*B - 2*A*B*cos(theta_rad));

    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3708
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	d := 0
	switch s {
	case "SUN":
		d = 7
	case "MON":
		d = 6
	case "TUE":
		d = 5
	case "WED":
		d = 4
	case "THU":
		d = 3
	case "FRI":
		d = 2
	case "SAT":
		d = 1
	}
	fmt.Println(d)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 512
N = int(input())
d = [int(input()) for x in range(N)]

x = len(d)

for i in range(x):
    for j in range(x - 1 - i):
        if d[j] < d[j + 1]:
            tmp = d[j]
            d[j] = d[j + 1]
            d[j + 1] = tmp
            
z = set(d)

print(len(z))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int spot[201010];

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        int sum = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&spot[i]);
            sum += abs(spot[i]-spot[i-1]);
        }
        spot[n+1] = 0;
        sum += abs(spot[n]);
        //printf("%d\n",sum);
        for(int i = 1; i <= n; i++)
        {
            int a1 = abs(spot[i] - spot[i-1]);
            int a2 = abs(spot[i+1] - spot[i]);
            int a3 = abs(spot[i+1] - spot[i-1]);
            printf("%d\n",(sum - a1 - a2 + a3));
        }
    }
    return 0;
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 空白を含む場合の文字列の受け取りはgetline(cin,s)
// cinとgetlineを同時に使う場合はcinの後にcin.ignore()で空白や改行をスキップしてからgetlineしないと空白を受け取ってしまう

typedef string::const_iterator S;
int n;
string s;

int number(S &i), term(S &i), expr(S &i), fact(S &i);

// 数字のパース
int number(S &i) {
	int ret = 0;
	while (isdigit(*i)) {
		ret *= 10;
		ret += *i-'0';
		i++;
	}
	return ret;
}

// 掛け算割り算(または数字単体)のパース
int term(S &i) {
	int ret = fact(i);
	while (1) {
		if (*i=='*') i++, ret *= fact(i);
		else if (*i=='/') i++, ret /= fact(i);
		else break;
	}
	return ret;
}

// termの足し算引き算のパース
int expr(S &i) {
	int ret = term(i);
	while (1) {
		if (*i=='+') i++, ret += term(i);
		else if (*i=='-') i++, ret -= term(i);
		else break;
	}
	return ret;
}

// かっこ付きの式のパース
int fact(S &i) {
	int ret = 0;
	if (*i=='(') {
		i++;
		ret = expr(i);
		i++;
	} else ret = number(i);
	return ret;
}

signed main() {
	cin >> n;
	while (n--) {
		cin >> s;
		S beg = s.begin();
		cout << expr(beg) << ln;
	}
}


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

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);

    int n, m;
    cin >> n >> m;
    vector<pair<ll, int>> v(n);
    rep(i, n)
    {
        cin >> v[i].first >> v[i].second;
    }
    sort(all(v));
    ll ans = 0;
    for (auto a: v) {
        ans += a.first * min(a.second, m);
        m -= a.second;
        if(m<=0) break;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

double calc(const vi &v){
	int n = v.size(), cnt[256] = {};
	double res = 0;
	rep(i, n) cnt[v[i]]++;
	rep(i, 256) if(cnt[i]){
		double t = cnt[i] * 1.0 / n;
		res -= t * log(t) / log(2);
	}
	return res;
}

int main(){
	int n, as, aa, ac;
	
	while(cin >> n, n){
		vi t(n);
		double e = INF;
		rep(i, n) cin >> t[i];
		
		rep(s, 16) rep(a, 16) rep(c, 16){
			vi v;
			int k = s;
			rep(i, n){
				k = (k * a + c) % 256;
				v.pb(((int)t[i] + k) % 256);
			}
			double te = calc(v);
			if(te + EPS < e){
				e = te;
				as = s; aa = a; ac = c;
			}
		}
		cout << as << " " << aa << " " << ac << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=201;
char s[MAXN],t[MAXN];
int len;
int main(){
	scanf("%s",s);scanf("%s",t);
	len=strlen(s);
	for(int i=len;i<(len<<1);++i) s[i]=s[i-len];
	for(int Left=0;Left<len;++Left){
		bool flag=true;
		for(int i=0;i<len;++i)
			if(s[Left+i]!=t[i]) {flag=false;break;}
		if(flag) {printf("Yes\n");return 0;}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<int> a;

int C(int n,int r){
    return (n & r) == r;
}

int f(int n){
    int ret = 0;
    for (int i = 0; i < n; i++) {
        ret = ret ^ (C(n - 1, i) * a[i]);
    }
    return ret;
}


int main(){
    int n;cin >> n;
    string s;cin >> s;
    a.resize(n-1);
    int c2 = 0, c1 = 0, c0 = 0;
    for (int i = 0; i < n-1; i++) {
        a[i] = abs(s[i+1] - s[i]);
        if(a[i] == 2) c2++;
        else if(a[i] == 1) c1++;
        else c0++;
    }
    if(c1 == 0){
        for (int i = 0; i < n-1; i++) {
            a[i] /= 2;
        }
        cout << (f(n-1)?2:0) << endl;
    }
    else{
        for (int i = 0; i < n-1; i++) {
            a[i] %= 2;
        }
        cout << f(n-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 5252
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string abc="abcdefghijklmnopqrstuvwxyz";
  string ans="";
  while(n){
    n--;
    ans+=abc[n%26];
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

void virus(){
       char ch;
       cin>>ch;
       if(ch >= 'a' and ch<='z') cout<<"a";
       else cout<<"A";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  int a,t,i,j=0,c,n=0,sum=0,x,y,b,p,m=0,q=0;

    string s;
    cin>>s;
    for(i=0; i<3; i++)
    {
        if(s[i]=='A')
        {
            m++;

        }
        else
        {
            n++;

        }
    }
    if(m>0 && n>0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;

}


Measured memory_bytes: 256
S=int(input())
T=list(input())
t=S//2
p=0
for i in range(t):
    if S%2==1:
        p=-1
        break
    elif T[i]!=T[i+t]:
        p=-1
        break
if p==-1 or t==0:
    print("No")
elif p==0:
    print("Yes")
    



Measured memory_bytes: 9136
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] str = br.readLine().toCharArray();
		int n = 0;
		for(char c : str){
			n = (n + Integer.parseInt("" + c))%9;
		}
		
		System.out.println((n == 0) ? "Yes" : "No");
	}
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    int N;
    cin >> N;
    VV<int> H(N, V<int>(3));
    FOR(i, 0, N) {
        cin >> H[i][0] >> H[i][1] >> H[i][2];
    }

    VV<LL> dp(N + 1, V<LL>(3, 0));

    FOR(i, 0, N) {
        FOR(j, 0, 3) {
            FOR(k, 0, 3) {
                if (j == k) {
                    continue;
                }
                chmax(dp[i + 1][k], dp[i][j] + H[i][k]);
            }
        }
    }
    print(MAX(dp[N]));

	return 0;
}


Measured memory_bytes: 11264