akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

const int max_n = 1e3 + 5;

char s[305][305];

int main() {
	make(n);
	FOR(i,0,n) {
		scanf("%s", s[i]);
	}
	int ans = 0;
	FOR(x,-(n-1),n) {
		bool ok = true;
		FOR(i,0,n) FOR(j,0,n) {
			if (s[i][(j+x+n)%n] != s[j][(i+x+n)%n]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			int y = max(x, -x);
			ans += (n - y);
		}
	}
	printf("%d\n", ans);
	
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};



int main(){
	int n;
	cin >> n;
	vi v(n),c(n);
	rep(i,n) cin >> v[i];
	rep(i,n) cin >> c[i];
	int ans = 0;
	for(int i = 0; i < (1<<n); i++){
		int ti = i,x = 0,y = 0;
		for(int j = 0; ti != 0; ti >>= 1,j++){
			if(ti&1){
				x += v[j];
				y += c[j];
			}
		}
		ans = max(ans,x-y);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999


struct cir{
    int x,y,r,c;
};

bool same(cir a,cir b){
    double r2 = (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    if((a.r+b.r)*(a.r+b.r)>r2)return true;
    else return false;
}

bool used(int n,const vi &vec){
    rep(i,vec.size()){
        int to = vec[i];
        if( (n&(1<<to)) != 0 )return false;
    }
    return true;
}

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<cir> data;
        
        rep(i,n){
            int x,y,r,c;
            cin>>x>>y>>r>>c;
            data.pb(cir{x,y,r,c});
        }
        
        
        vector<int> G[30];
        
        for(int i=data.size()-1;i>=0;i--){
            for(int j=i-1;j>=0;j--){
                if(same(data[i],data[j])){
                    G[i].pb(j);
                }
            }
        }
        
        static bool dp[1<<24];
        rep(i,1<<n)dp[i]=false;
        dp[(1<<n)-1]=true;
        
        
        for(int i=(1<<n)-1;i>=0;i--){
            if(!dp[i])continue;
            rep(j,n){
                if( (i&(1<<j) )==0 )continue;
                for(int k=j+1;k<n;k++){
                    if( (i&(1<<k) )==0 )continue;
                    if( data[j].c==data[k].c && used(i,G[j]) && used(i,G[k]) ) dp[(i^(1<<j))^(1<<k)] = true;
                }
            }
        }
        
        int ans=100;
        for(int i=(1<<n)-1;i>=0;i--){
            if(!dp[i])continue;
            ans = min(ans,__builtin_popcount(i));
        }
        cout<<n-ans<<endl;
    }
}

Measured memory_bytes: 19488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcm(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcm(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcm(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int a, b;
    cin >> a >> b;
    int count = 1;
    int count_a = 0;
    bool ok = false;
    if(count >= b) ok = true;
    while(!ok) {
        count--;
        count += a;
        count_a++;
        if(count >= b) ok = true;
    }
    cout << count_a << endl;
}

Measured memory_bytes: 3616
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

N,M = ints_raw()
ABs = []
for n_i in xrange(N):
    ABs.append(ints_raw())
ABs.sort()

ans = 0
kosuu = 0
for A,B in ABs:
    n_kosuu = kosuu + B
    if n_kosuu>=M:
        ans += (M-kosuu)*A
        kosuu = M
        break
    else:
        ans += A*B
        kosuu = n_kosuu

print ans
    

Measured memory_bytes: 18876
'''
「異なる個数を選んで足した場合、それらが一致することは絶対にない」
N=5, k=3のとき、最小の数 3 から、最大の数 12 まで「連続する整数を作ることができる」
k 個足してできる最小の整数を求める (a とする)
k 個足してできる最大の整数を求める (b とする)
出来上がる整数は b−a+1 個である
'''
N, k = map(int, input().split())
ans = 0
MOD = 10**9+7
for i in range(k, N+2):
  minNum = i*(i-1)//2 #0+1+...+(k-1)
  maxNum = i*(2*N-i+1)//2 #(N-k+1)+...+(N-1)+N
  ans += maxNum - minNum + 1
print(ans%MOD)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int mai;
		int nokori;
		if(d>=e) {
			mai = e;
			nokori = d-e;
		}else {
			mai = d;
			nokori = e-d;
		}

		int money = 0;

		if(a+b > 2*c) {
			money = 2*c*mai;
			if(d>=e) {
				money += nokori * a;
			}else {
				money += nokori*b;
			}
		}else{
			money += a*d;
			money += b*e;
		}

		int yokei;
		if(d>=e) {
			yokei = 2*c*d;
		}else {
			yokei = 2*c*e;
		}

		int kingaku = 0;
		if(yokei>=money) {
			kingaku = money;
		}else {
			kingaku = yokei;
		}


		System.out.println(kingaku);
	}

}

Measured memory_bytes: 23380
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int hour = scanner.nextInt();
        final int minute = scanner.nextInt();
        final int second = scanner.nextInt();
        if (hour == -1 && minute == -1 && second == -1) {
          return;
        }
        VideoTape videoTape = new VideoTape(hour, minute, second);
        System.out.println(videoTape.remainingTime());
        System.out.println(videoTape.remainingTime3());
      }
    }
  }
}


class VideoTape {

  private final int hour;
  private final int minute;
  private final int second;

  private final DateTimeFormatter displayDateFormat;

  VideoTape(int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
    displayDateFormat = DateTimeFormatter.ofPattern("HH:mm:ss");
  }

  String remainingTime() {
    return LocalDateTime
        .of(0, 1, 1, 2, 0)
        .minusHours(hour)
        .minusMinutes(minute)
        .minusSeconds(second)
        .format(displayDateFormat);
  }

  String remainingTime3() {
    return LocalDateTime
        .of(0, 1, 1, 6, 0)
        .minusHours(hour * 3)
        .minusMinutes(minute * 3)
        .minusSeconds(second * 3)
        .format(displayDateFormat);
  }
}

Measured memory_bytes: 32640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define N_MAX 200002
ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

int main(){
    init();
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll ans = 0;
    ll N, M, K;
    cin >> N >> M >> K;
    for(ll x = 1; x <= N; x++){
        for(ll y = 1; y <= M; y++){
            ll tmp = (((x*(x-1))/2+((N-x)*(N-x+1))/2)%MOD)*M;
            tmp %= MOD;
            tmp += (((y*(y-1))/2+((M-y)*(M-y+1))/2)%MOD)*N;
            tmp %= MOD;
            ans += tmp;
            ans %= MOD;
        }
    }
    //cout << ans << endl;
    ans *= inv[N*M];
    ans %= MOD;
    ans *= inv[N*M-1];
    ans %= MOD;
    ans *= comb(N*M, K);
    ans %= MOD;
    ans *= comb(K, 2);
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main() {

	string S;
	cin >> S;

	int count = 0;

	for (int i = 0; i < S.size() / 2; ++i)
	{
		if (S[i] != S[S.size() - 1 - i]) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,b[123],c;
int main(){
	cin>>n;
	for(int i=1;i<n;i++)cin>>b[i];
	b[0]=123456;
	b[n]=123456;
	for(int i=0;i<n;i++){
		if(b[i]<b[(i+1)])c+=b[i];
		else c+=b[(i+1)];
	}
	cout<<c<<endl;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
 
for i in range(n-m+1):
    for j in range(n-m+1):
        ans=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    ans=False
        if ans:
            print('Yes')
            exit(0)
 
print('No')

Measured memory_bytes: 3064
n,p=map(int,input().split())
l=[]

for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-(x[0]*(100-p)+x[1]*p))
z=0
for i in range(n):
    z+=-l[i][1]*p
i=0
while z<0:
    z+=l[i][0]*(100-p)+l[i][1]*p
    i+=1
print(i)

Measured memory_bytes: 31368
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll sum=0;
    for(ll i=0;i<N;++i)sum+=A[i];
    ll ans=llabs(sum-2*A[0]);
    ll unt=A[0];
    for(ll i=1;i<N-1;++i){
        unt+=A[i];
        chmin(ans,llabs(sum-2*unt));
    }
    prt(ans)

    return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()

    def choose2(a):
        return a * (a-1) // 2

    print(choose2(n+m) - n * m)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll s;
ll x[200005],p[200005];
ll now[200005];

ll labs(ll a){
	if(a<0LL)return -a;
	return a;
}

int main(void){
	scanf("%d%lld",&n,&s);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x[i],&p[i]);
		now[i]=p[i];
	}
	int l=0,r=n-1;
	ll ans=0;
	while(l<=r){
		if(s<=x[l]){
			ans+=x[r]-s;
			break;
		}
		if(x[r]<=s){
			ans+=s-x[l];
			break;
		}
		if(now[l]>=now[r]){
			ans+=x[r]-x[l];
			while(l<r && now[l]>=now[r]){
				now[l]+=now[r];
				r--;
			}
		}else{
			ans+=x[r]-x[l];
			while(l<r && now[l]<now[r]){
				now[r]+=now[l];
				l++;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3584
n = input()
 
num = len(n)
 
if num == 1:
  print(n)
elif num == 2:
  print(9)
elif num == 3:
  result = (int(n)-100+1) + 9
  print(result)
elif num == 4:
  print(909)
elif num == 5:
  result = (int(n)-10000+1) + 900 + 9
  print(result)
else:
  print(90909)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k;
	cin >> n;
	vector<long double> t(n + 1), v(n + 1), s(n + 1);
	for (i = 1; i <= n; i++) cin >> t[i];
	for (i = 1; i <= n; i++) cin >> v[i];

	for (i = 0; i <= n; i++) {
		if ((i == 0) || (i == n)) s[i] = 0;
		else s[i] = min(v[i], v[i + 1]);
	}

	for (i = 1; i <= n; i++) {
		s[i] = min(s[i], s[i - 1] + t[i]);
	}

	for (i = n - 1; i >= 0; i--) {
		s[i] = min(s[i], s[i + 1] + t[i + 1]);
	}

	long double ans, tt, ss, tv;
	ans = 0;
	for (i = 0; i < n; i++) {
		//tt = max(s[i + 1] - s[i], s[i] - s[i + 1]);
		tt = abs(s[i + 1] - s[i]);
		ans += tt * (s[i + 1] + s[i]) / 2.0;
		
		tt = t[i + 1] - tt;		// free time
		ss = max(s[i + 1], s[i]);

		if (ss + tt / 2.0 > v[i + 1]) {
			tv = v[i + 1] - ss;
			ans += (tt - tv * 2.0) * v[i + 1];
			ans += tv * (v[i + 1] + ss);
		}
		else {
			ans += tt * (ss + tt / 4);
		}
	}
	cout << setprecision(10) << fixed << ans << "\n";

	return 0;
}



Measured memory_bytes: 632
/*
 * アルゴリズムとしてはチケットの枚数分のネットワークをレイヤ構造で持ち
 * 各々のレイヤから上位レイヤへはチケットを使った場合に遷移するようにする
 * 上位レイヤから下位レイヤには遷移することができないようにし，
 * 最下位レイヤの始点から終点と同じ点を表すすべてのレイヤの点までの最短経路を求める．
 *
 * (イメージ)
 *      T`T`T`  
 *      |/|/|   S=始点, o=点, T`=終点 |=辺 /=レイヤ下位から上位への有効辺
 *      o o o   
 *      |/|/|   S->T`までの距離で最短のものを求め出力する
 *      S o o   
 *Layer 0 1 2   
 *
 **/

#include <iostream>
#include <map>
#include <limits.h>

#define rep(i,s,t) for(int i=s;i<t;i++)

using namespace std;

//c層目のid値を返す関数
int id2cid(int c,int id){
	return c*1000+id;
}

//dijkstraアルゴリズム
//特に無加工，距離を持った隣接を表すgraphと各点までの距離を保持するdis,始点ssを入力
//計算結果はdisに保持し，返り値は無し
void dijkstra(map<int,map<int,int> > &graph,map<int,int>  &dis,int ss){
	//未確定点を保持する集合multimap，距離をkey,点idをvalueとする
	multimap<int, int> T;
	//注目する点pのid値
	int pid;
	//始点をまず入力する
	T.insert(make_pair(0,ss));
	//未確定点がなくなるまで
	while(!T.empty()){
		//未確定の中で一番距離が小さい要素(mapの先頭)を取得し注目点pを得る
		pid=(*(T.begin())).second;
		//点pを未確定点集合から削除する
		T.erase(T.begin());

		//pに隣接する点について
		for(map<int,int>::iterator it=graph[pid].begin();it!=graph[pid].end();it++){
			//隣接点のid値cidとその点までの距離distを取得
			int cid=(*it).first;
			int dist=(*it).second;
			//隣接点が未確定点集合に含まれない，もしくは暫定の距離より小さい場合
			//未確定点集合の隣接点の距離を始点から注目点までの距離＋注目点からの距離に更新する
			if((dis.find(cid)!=dis.end() &&  dis[cid]>dis[pid]+dist) ||
				dis.find(cid)==dis.end()){
					T.insert(make_pair(dis[pid]+dist,cid));			
					dis[cid]=dis[pid]+dist;
			}
		}
	}
}

int main(void){
	
	int c,n,m,s,d;
	while(cin >> c >> n >> m >> s >> d){
		if(c==0) break;

		//グラフ構造用意
		//mapを用いて辺i,jのコストcで隣接関係を表現
		map<int,map<int,int> > graph;

		//m路線に対して
		rep(i,0,m){
			int a,b,f;
			cin >> a >> b >> f;

			//グラフをc+1個の層構造とする
			rep(j,0,c+1){
				//j層目のグラフでは通常料金の移動コストで辺を張る
				//id2cid(j,id)でj層目の点idを示すid値に変換する
				//点は最大でも500点しかないため，1000桁目以上がn層目とする.
				//ex(0層目の点125は id=125,8層目の点125は8125)となる．
				graph[id2cid(j,a)][id2cid(j,b)]=f;
				graph[id2cid(j,b)][id2cid(j,a)]=f;
				//j層目からj+1層目へは割引料金を用いた移動コストの辺を張る
				//j層目からj-1層目への辺がないため階層が上がるに連れて下がることはできない
				//j層目はすなわちj回チケットを利用した枚数に相当する．
				if(j<c){
					graph[id2cid(j,a)][id2cid(j+1,b)]=f/2;
					graph[id2cid(j,b)][id2cid(j+1,a)]=f/2;
				}
			}
		}
		rep(j,0,c+1){
			//各レイヤからダミー終点INT_MAXまで辺をはる
			graph[id2cid(j,d)][INT_MAX]=0;
		}
		//各点の最短距離を保持するmap
		map<int,int>  dis;
		//通常のダイクストラで始点sからの各点への最短距離を求め，計算結果を変数disに保持する
		dijkstra(graph,dis,id2cid(0,s));

		//結果出力
		cout << dis[INT_MAX] << endl;
	}

	return 0;
}

Measured memory_bytes: 2040
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
anst = na(100005,0)


  (1..100).each do |x|
    (1..100).each do |y|
      (1..100).each do |z|
        anst[x**2+y**2+z**2+x*y+x*z+y*z] += 1
      end
    end
  end
  
puts anst[1..n]


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

int main() {
	int N;
	cin >> N;
	string contest = N < 1000 ? "ABC" : "ABD";
	cout << contest << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using P = pair<int, int>;

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

  int N; cin >> N;
  vector<P> ab(N), cd(N);
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    ab[i] = P(a, b);
  }
  for (int i = 0; i < N; i++) {
    int c, d; cin >> c >> d;
    cd[i] = P(c, d);
  }
  sort(cd.begin(), cd.end());

  vector<bool> check(N);
  for (int i = 0; i < N; i++) {
    int& c = cd[i].first;
    int& d = cd[i].second;
    int k = -1;
    for (int j = 0; j < N; j++) {
      if (check[j]) continue;
      int& a = ab[j].first;
      int& b = ab[j].second;
      if (c > a && d > b && (k < 0 || b > ab[k].second))
        k = j;
    }
    if (k >= 0) check[k] = true;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) if (check[i]) ans++;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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 main(){
  string s; cin >> s;
  ll ans1 = 0, ans2 = 0, w = 0, b = 0;
  rep(i,s.size()){
    if(s[i] == 'W'){
      ans1 += i-w;
      w++;
    }
  }
  rrep(i,s.size()){
    if(s[i] == 'B'){
      ans2 += s.size()-i-b;
      b++;
    }
  }
  cout << min(ans1,ans2);
  cout << "\n";
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		System.out.println((n-a+1)*(n-b+1));
	}
		
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 20820
var
    a,b,c,d,e,k:integer;
begin
    readln(a);
    readln(b);
    readln(c);
    readln(d);
    readln(e);
    readln(k);
    if e-a>k then writeln(':( ');
    if e-a<=k then writeln('Yay! ');
end.

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


struct UnionFind {
    vector<int> par, rank;

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

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

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

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};


int main() {
    int N; cin >> N;
    UnionFind uf(2 * N);
    rep(i, N - 1) {
        int a, b, w; cin >> a >> b >> w;
        a--; b--;
        if (w & 1) {
            uf.unite(a, b + N);
            uf.unite(a + N, b);
        }
        else {
            uf.unite(a, b);
            uf.unite(a + N, b + N);
        }
    }

    rep(i, N) {
        cout << (uf.same(0, i) ? 0 : 1) << endl;
    }
}

Measured memory_bytes: 2048
#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 998244353;
char s[2001];
int c[4001][2];
int dp[4001][4001];

int main() {
    int n, i, j;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    for (i = 0; i < n * 2; i++) {
        c[i + 1][0] = c[i][0];
        c[i + 1][1] = c[i][1];
        
        if (i >= n) continue;
        
        if (s[i] == '0') {
            c[i + 1][0] += 2;
        } else if (s[i] == '1') {
            c[i + 1][0]++;
            c[i + 1][1]++;
        } else {
            c[i + 1][1] += 2;
        }
    }
    
    dp[0][0] = 1;
    
    for (i = 0; i < n * 2; i++) {
        for (j = 0; j < n * 2; j++) {
            if (dp[i][j] == 0) continue;
            
            if (c[i + 1][0] >= j + 1) {
                dp[i + 1][j + 1] += dp[i][j];
                if (dp[i + 1][j + 1] >= mod) dp[i + 1][j + 1] -= mod;
            }
            if (c[i + 1][1] >= i - j + 1) {
                dp[i + 1][j] += dp[i][j];
                if (dp[i + 1][j] >= mod) dp[i + 1][j] -= mod;
            }
        }
    }
    
    printf("%d\n", dp[n * 2][c[n * 2][0]]);
    
    return 0;
}


Measured memory_bytes: 60416
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] num = new int[10];
			while(n-->0){
				num[scanner.nextInt()]++;
			}
			for(int a:num){
				if(a==0)
					System.out.println('-');
				else{
					char[] c = new char[a];
					Arrays.fill(c, '*');
					System.out.println(c);
				}
			}
		}
	}
}

Measured memory_bytes: 51864
import scala.io.StdIn
import java.io.{BufferedReader,InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(n, t) = in.readLine.split(" ").map(_.toInt)
  val a = in.readLine.split(" ").map(_.toLong)

  val ans = a./:(t.toLong,0L)((acc,ti) => {
    val dur = ti - acc._2
    if(dur < t) (acc._1 + dur, ti)
    else (acc._1 + t, ti)
  })._1

  println(ans)
}

Measured memory_bytes: 54508
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>

using ll = long long;

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

string s; int n;

bool works(int k)
{
    for (int i = n-k; i <= k-1; i++) if (s[i] != s[n-k]) return false; //fixed is not continuous
    return true;
}

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    
    cin >> s;
    n = s.size();
    
    int lo = 1;
    int hi = n;
    
    while (hi > lo)
    {
        int mid = (hi+lo+1)/2;
        if (works(mid)) //increase
        {
            lo = mid; //inclusive
        }
        else
        {
            hi = mid-1; //exclusive
        }
        
    }
    
    cout << lo << endl;
    
    return 0;
    
}




Measured memory_bytes: 512
#include <stdio.h>

typedef struct {int x,y;} Pair;

Pair pair[30];
int  w,n;

int solve(int a,int b) {
	for(b;b<n;b++) {
		if(a==pair[b].x) {
			return solve(pair[b].y,b+1);
		}else if(a==pair[b].y) {
			return solve(pair[b].x,b+1);
		}
	}
	return a;
}

int main(void) {
	int i,answer[30];

	scanf("%d",&w);
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%d,%d",&pair[i].x,&pair[i].y);
	}
	for(i=1;i<=w;i++) {
		answer[solve(i,0)-1]=i;
	}
	for(i=0;i<w;i++) {
		printf("%d\n",answer[i]);
	}
	return 0;
}

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

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

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    std::string str;
    std::cin >> str;
    int papers = 0;
    for (char c : str) {
        if (c == 'p') {
            ++papers;
        }
    }
    std::cout << (str.length() / 2 - papers) << '\n';
    return 0;
}

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

typedef pair<int, int> P;
#define int long long

#define MOD 1000000007

int N;
int T[100000];
int A[100000];

signed main() {
    cin >> N;
    int t_max = 0;
    int a_max = N-1;
    for(int i = 0; i < N; ++i) {
        cin >> T[i];
        if(T[i] > T[t_max]) t_max = i;
    }
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for(int i = N-1; i >= 0; --i) {
        if(A[i] > A[a_max]) a_max = i;
    }
    int ans = 0;
    if(T[t_max] == A[a_max] && t_max <= a_max) {
        int t_ans = 1;
        int tt = T[0];
        for(int i = 1; i < t_max; ++i) {
            if(T[i] > tt) tt = T[i];
            else t_ans = (t_ans * T[i]) % MOD;
        }
        int aa = A[N-1];
        int a_ans = 1;
        for(int i = N-2; i > a_max; --i) {
            if(A[i] > aa) aa = A[i];
            else a_ans = (a_ans * A[i]) % MOD;
        }
        ans = (t_ans * a_ans) % MOD;
        for(int i = t_max+1; i <= a_max-1; ++i) {
            ans = (ans * T[i]) % MOD;
        }
    }

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

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

    vector<int> L(N);
    rep(i, N)
    {
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int x = max(L[i] - L[j], L[j] - L[i]);
            int y = L[i] + L[j];
            auto upper = lower_bound(L.begin() + j, L.end(), y) - 1;
            auto lower = upper_bound(L.begin() + j, L.end(), x);
            ans += upper - lower;
        }
    }

    cout << ans << endl;
}


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

#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << endl;
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define fori(i, a, b) for(int i(a), ThkMk(b); i <= ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef unsigned long long ulli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

///-----------------------------------------------------------
///-----------------------------------------------------------

const lli R = 3e3, C = 3e3;

bool calculado[R + 1][C + 1][4];
lli r, c, k, mat[R + 1][C + 1], dp[R + 1][C + 1][4];

///-----------------------------------------------------------

void leerDatos()
{
    cin >> r >> c >> k;
    for (lli i=0; i<k; ++i)
    {
        lli x, y, v;
        cin >> x >> y >> v;
        mat[x][y] = v;
    }
}

lli f(lli x, lli y, lli p)
{
    if (!calculado[x][y][p])
    {
        if (x > 1)
        {
            if (y > 1)
            {
                if (p && mat[x][y])
                    dp[x][y][p] = max(max(mat[x][y] + f(x, y - 1, p - 1), f(x, y - 1, p)), mat[x][y] + f(x - 1, y, 3));
                else
                    dp[x][y][p] = max(f(x, y - 1, p), f(x - 1, y, 3));
            }
            else
            {
                if (p && mat[x][y])
                    dp[x][y][p] = mat[x][y] + f(x - 1, y, 3);
                else
                    dp[x][y][p] = f(x - 1, y, 3);
            }
        }
        else
        {
            if (y > 1)
            {
                if (p && mat[x][y])
                    dp[x][y][p] = max(mat[x][y] + f(x, y - 1, p - 1), f(x, y - 1, p));
                else
                    dp[x][y][p] = f(x, y - 1, p);
            }
            else
            {
                if (p && mat[x][y])
                    dp[x][y][p] = mat[x][y];
                else
                    dp[x][y][p] = 0;
            }
        }

        calculado[x][y][p] = true;
    }
    return dp[x][y][p];
}

int main()
{   _

    leerDatos();

    cout << f(r, c, 3) << endl;

    return 0;
}

Measured memory_bytes: 390952
// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
	fast;
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		ll n,res=0;
		cin >> n;
		ll a[n];
		for(ll i=0;i<n;i++)
			cin>>a[i];
		ll pre[n-1];
		pre[0] = a[0];
		for(ll i=1;i<n-1;i++)
		{
			pre[i] = pre[i-1] + a[i];
		}
		for(ll i=0;i<n-1;i++)
		{
			res = (res%mod + (pre[i]%mod * a[i+1]%mod)%mod)%mod;
		}
		cout<<res<<"\n";
	}
	return 0;
}

Measured memory_bytes: 6776
#include<stdio.h>
int main (void){

	int x,y,w1;
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0&&y==0)break;
else if (x<y){
	w1=x;
	x=y;
	y=w1;
	printf("%d %d\n",y,x);}

else
printf("%d %d\n",y,x);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d=0,e=0,i;
  cin>>a;
  for(i=1;i<=a;i++)
  {
      cin>>b>>c;
      if(b==c)d++;
      else d=0;
      if(d>=3)e=1;
  }
  if(e==1)cout<<"Yes\n";
  else cout<<"No\n";
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, z, w;

int main() {
	cin >> n >> z >> w;
	ll a[n];
	for(ll i = 0; i < n; i++){
		cin >> a[i]; 
	}
	ll max;
	if(n == 1){
		max = (a[0]-w > 0)? a[0]-w : w-a[0];
	}
	else{
		ll abs1 = (a[n-1]-w > 0)? a[n-1]-w : w-a[n-1];
		ll abs2 = (a[n-1]-a[n-2] > 0)? a[n-1]-a[n-2] : a[n-2]-a[n-1];
		max = (abs1 > abs2)? abs1 : abs2;
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
place = {}
for i in range(N):
    place[int(input())] = i

seq = 0
seq_max = 0
prev = 0
for i in range(1, N+1):
    if place[i] >= prev:
        seq += 1
    else:
        seq = 1
    prev = place[i]
    seq_max = max(seq, seq_max)
print(N - seq_max)


Measured memory_bytes: 71896
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F551C':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a, b, c = read_int_list()
    x = 10 * a + b + c
    y = 10 * b + a + c
    z = 10 * c + a + b
    res = max([x, y, z])
    print(res)


main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ll n,d,a;
    cin >> n >> d >> a;
    vector<ll> imos(n+10);
    vector<ll> x(n);
    vector<P> v(n);
    rep(i,n){
        cin >> v[i].first >> v[i].second;
    }
    vector<ll> h(n);
    sort(v.begin(),v.end());
    rep(i,n){
        h[i] = v[i].second;
        x[i] = v[i].first;
    }
    ll ans = 0;
    rep(i,n){
        if(h[i]+imos[i]>0){
            ll cnt = (h[i]+imos[i]+a-1)/a;
            imos[i] -= cnt * a;
            auto id = upper_bound(x.begin(),x.end(),x[i]+2*d) - x.begin();
            imos[id]+=cnt*a;
            ans+=cnt;
        }
        imos[i+1]+=imos[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

ll n,f[100][10],p[100][11];

int main()
{
    int A,B,N;
    cin >> N >> A >> B;
    cout << min(N*A,B) << endl;
}

Measured memory_bytes: 3124
n,m,c = map(int, input().split())
data_b = list(map(int, input().split()))
res = 0
digit = 0
for i in range(n):
  data_a = list(map(int, input().split()))
  for j in range(m):
    digit += data_a[j]*data_b[j]
  if digit + c > 0:
    res += 1
  digit = 0
print(res)

Measured memory_bytes: 3060
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s = "Christmas";
  while(n <= 24) {
    n++;
    s += " Eve";
  }
  cout << s << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000
#define MAX 200001
#define PI 3.141592653589793

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    ll N;
    cin >> N;
    for(ll h = 1; h <= 3500; h++){
        for(ll n = 1; n <= 3500; n++){
            if(4*h*n - N*n - N*h <= 0) continue;
            if((N * h * n) % (4*h*n - N*n - N*h) == 0){
                ll w = (N * h * n) / (4*h*n - N*n - N*h);
                cout << h << ' ' <<  n << ' ' << w << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3628
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2000 + 5;
const int M = 201;
const int Q = 2e5 + 5;
const int OO = 2e9;
const int mod = 1e9 + 7;

int n,a[N],l,ans;

void init() {
}

int main() {

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

    cin >> n;

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

    sort(a,a+n);

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            l = lower_bound(a+j+1,a+n,a[i]+a[j])-a;
            ans += l-1-j;
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.shift();
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140152
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }



void solve() {
    int x;
    cin >> x;
    int g = gcd(360,x);
    int mul = 360 / g * x;
    cout << mul / x << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int total = 0;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    
    total += r - l + 1; 
  }

  cout << total << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void) {
    int R[MAX], n;
    
    cin >> n;
    for(int i=0;i<n;i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


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

#define scd second;
#define fst first;
#define mkp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

int N=2e5+10, mod=2019;
vint rmod(N), rimod(N);

ll inv_mod(ll b, ll m){
	ll a=m, r, q, x=0, y=1;
	while(b){
		r=a%b;
		q=a/b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	return (x+m)%m;
}

ll solve(string &s, int l, int r){
	if(l>=r){
		return 0;
	}
	int m=(l+r)>>1, v=0;
	ll ret1=solve(s,l,m);
	ll ret2=solve(s,m+1,r);
	vlong cnt1(mod+1,0), cnt2(mod+1,0);
	for(int i=m, p=0; i>=l; i--,p++){
		v=(v+(s[i]-'0')*rmod[p])%mod;
		cnt1[v]++;
	}
	v=0;
	for(int i=m+1, p=1; i<=r; i++,p++) {
		v=(v*10+(s[i]-'0'))%mod;
		cnt2[(mod-v)*rimod[p]%mod]++;
	}

	// cout<<l<<" "<<m<<" "<<r<<endl;
	// for(int i=0; i<=mod; i++){
	// 	if(cnt1[i]) cout<<i<<","<<cnt1[i]<<" | ";
	// }
	// cout<<endl;

	// for(int i=0; i<=mod; i++){
	// 	if(cnt2[i]) cout<<i<<","<<cnt2[i]<<" | ";
	// }
	// cout<<endl;
	ll ret=0;
	for(int i=0; i<=mod; i++){
		ret+=cnt1[i]*cnt2[i];
	}
	// cout<<ret<<endl<<"........"<<endl;;
	return ret+ret1+ret2;
}

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

	rmod[0]=1;
	rimod[0]=1;
	for(int i=1; i<N; i++){
		rmod[i]=rmod[i-1]*10%mod;
		rimod[i]=inv_mod(rmod[i],mod);
	}
	// for(int i=0; i<10; i++){
	// 	cout<<rmod[i]<<" "<<rimod[i]<<endl;
	// }
	// cout<<endl;

	string s;
	cin>>s;
	int n=s.length();
	// for()
	cout<<solve(s,0,n-1)<<endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

int dp[100][100];
int a[100], b[100];

int main() {
	int n;
	cin >> n;
	REP(i, n) scanf("%d %d", &a[i], &b[i]);
	
	fill(dp[0], dp[100], INF);
	REP(i, n) dp[i][i] = 0;
	FOR(w, 1, n) REP(i, n - w) FOR(j, i, i + w) {
		dp[i][i + w] = min(dp[i][i + w], dp[i][j] + dp[j + 1][i + w] + a[i] * b[j] * a[j + 1] * b[i + w]);
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void){
    int h,w;
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0 && w == 0){
            break;
        }
        int i;
        for(i=0;i<w;i++){
            printf("#");
        }//最初の行
        printf("\n");
        for(i=1;i<h-1;i++){
            int j;
            printf("#");
            for(j=1;j<w-1;j++){
                printf(".");
            }
            printf("#\n");
        }//中間
        for(i=0;i<w;i++){
            printf("#");
        }//最後の行
        printf("\n\n");
    }
    return 0;
}


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

int main() {
    int n, f, sum=0;
    cin >> n;
    int list[n];
    for (int i = 0; i < n; i++)
    {
        cin >> list[i];
        sum += list[i];
    }
    int m,p,x;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> p >> x;
        cout << sum + x - list[p-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

S = input()
T = input()

st = {}
ts = {}

yes = "Yes"
no = "No"

ans = yes
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s not in st and t not in ts:
        st[s] = t
        ts[t] = s
    elif s in st:
        if st[s] != t:
            ans = no
            break
    else:
        ans = no
        break
print(ans)


Measured memory_bytes: 41840
n = int(input())
Ts = list(map(int, input().split()))
As = list(map(int, input().split()))

prev = 0
inds = []
for t in Ts:
    if prev < t:
        inds.append((t,1))
    else:
        inds.append((t,0))
    prev = t
indsA = []
prev = 0
for a in As[::-1]:
    if prev < a:
        indsA.append((a,1))
    else:
        indsA.append((a,0))
    prev = a
# print(inds, indsA[::-1])
# if Ts[-1] != As[0]:
#     print(0)
#     exit()
ans = 1
MOD = 10**9 + 7
for it, ia in zip(inds, indsA[::-1]):
    # print(it,ia)
    if it[1] == 1 and ia[1] == 1:
        if it[0] != ia[0]:
            # 矛盾
            print(0)
            exit()
    elif it[1] == 1 and ia[1] == 0:
        # print("t",it,ia)
        if it[0] > ia[0]:
            print(0)
            exit()
    elif it[1] == 0 and ia[1] == 1:
        # print("a",it,ia)
        if it[0] < ia[0]:
            print(0)
            exit()
    else:
        mn = min(it[0],ia[0])
        ans *= mn
        ans %= MOD
    # print(it,ia,ans)
print(ans)


Measured memory_bytes: 32036