akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int 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++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct edge {int to,cap,rev;};
const int MAX_V=102,inf=1e18;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void init(int V){
	rep(i,V) G[i].clear();
}
void add_edge(int from, int to, int cap){
	edge e1={to,cap,G[to].size()},e2={from,0,G[from].size()};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
int dfs(int v,int t,int f){
	if(v==t) return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(true){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while( (f=dfs(s,t,inf))>0 ) flow+=f;
	}
}


signed main(){
	int N;
	cin>>N;
	int S = N, T = N+1;
	int off = 0;
	int allsum = 0;
	rep(i,N){
		int x;
		cin>>x;
		allsum += x;
		if(x>=0){
			add_edge(S,i,x);
			add_edge(i,T,0);
		}else{
			add_edge(S,i,0);
			add_edge(i,T,-x);
			off += x;
		}
	}
	rep1(i,N){
		for(int j=i*2;j<=N;j+=i){
			add_edge(j-1,i-1,inf);
		}
	}
	int f = max_flow(S,T) + off;
	cout << allsum - f << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {

	int A, B, C, D, P;

	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &D);
	scanf("%d", &P);

	printf("%d\n", min(A * P, B + ((C < P) ? D * (P - C) : 0)));

	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a < 1 || a>100 || b < 1 || b>100) {
		cout << "error\n";
		return 0;
	}
	cout << a * b << endl;
	return 0;
}

Measured memory_bytes: 3596
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		BigDecimal a = new BigDecimal(sc.nextBigInteger()).multiply(sc.nextBigDecimal());
        System.out.println(a.setScale(0, BigDecimal.ROUND_DOWN));
	}
}

Measured memory_bytes: 37464
#include <iostream>

using namespace std;

int main() {
    int n;
    bool approved = true;
    cin >> n;

    while (n--) {
        int num;
        cin >> num;
        if (num % 2 == 0 && (num % 5 != 0 && num % 3 != 0)) {
            approved = false;
            break;
        }
    }
    cout << (approved ? "APPROVED\n" : "DENIED\n");

    return 0;
}


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

using namespace std;

int N;
string s;

void solve()
{
  cin >> N >> s;
  int count=0;
  s.push_back('#');
  for(int i=0; i+1 < s.size(); i++)
  {
    if(s[i] != s[i+1])
      count++;
  }
  cout << count << endl;
}
  
int main()
{
  solve();
  return 0;
}
  
        
        

Measured memory_bytes: 3740
use std::cmp;

fn main(){
    getline();
    let buf = getline();
    let str = buf.trim();
    let mut cnt1 = [0; 30];
    let mut cnt2 = [0; 30];
    let mut best = 0;
    
    for e in str.bytes() {
        cnt1[e as usize - 'a' as usize] += 1;
    }
    
    for e in str.bytes() {
        let i = e as usize - 'a' as usize;
        cnt1[i] -= 1;
        cnt2[i] += 1;
        let mut c = 0;
        for j in 0..30 {
            c += if (cnt1[j] * cnt2[j] > 0){1}else{0};
        }
        best = cmp::max(best, c);
    }
    println!("{}", best);
}

fn getline() -> String{
    let mut r = String::new();
    std::io::stdin().read_line(&mut r).ok();
    return r;
}


Measured memory_bytes: 4352
import fractions
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if K > max(A):
    print('IMPOSSIBLE')
elif K % gcd_list(A) != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 16280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 - (y2-y1);
    int y3 = y2 - (x1-x2);
    int x4 = x1 - (y2-y1);
    int y4 = y1 - (x1-x2);
    printf("%d %d %d %d\n", x3, y3, x4, y4);

    return 0;
}

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

int main() {
double N, A;
  int n;
  A = 0.5000000000000000000;
  cin >> N;
  n = N;
  if(n%2 == 0)
    cout << A << endl;
  else
printf("%.20lf\n", (N+1)/2/N);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int main(){
	fast;
	ll t,n,d; cin>>n>>d;
	vector<double> arr(n);
	for(auto i=0;i<n;++i){
		ll x,y; cin>>x>>y;
		arr[i]=(double)sqrt(x*x+y*y);
	}
	ll cnt=0;
	for(auto i=0;i<n;++i){
		if(d-arr[i]>=0)++cnt;
	}
	cout<<cnt<<'\n';
	return 0;
}
//prime func
//subset production
//factorization
 
//dfs/bfs
//prim's/kruskal's
//dijikstra/warshall-floyd
//tree traversal
//DP - Recursion

Measured memory_bytes: 4760
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<ll> sum(n);
    sum[0]=a[0];
    for(int i=1;i<n;i++){
        sum[i]=sum[i-1]+a[i];
    }
    ll ret=LLONG_MAX;
    for(int i=1;i<n-2;i++){
        ll s=sum[i]/2;
        int x=lower_bound(sum.begin(),sum.begin()+i+1,s)-sum.begin();
        ll t=sum[i]+(sum[n-1]-sum[i])/2;
        int y=lower_bound(sum.begin()+i+1,sum.end(),t)-sum.begin();
        ll b,c,d,e;
        for(int j=max(0,x-1);j<=min(i,x);j++){
            for(int k=max(i+1,y-1);k<=min(n-2,y);k++){
                b=sum[j];
                c=sum[i]-sum[j];
                d=sum[k]-sum[i];
                e=sum[n-1]-sum[k];
                ret=min(ret,max({b,c,d,e})-min({b,c,d,e}));
            }
        }
    }
    cout<<ret<<endl;
}

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

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

  cout << (N * N - N) / 2 + (M * M - M) / 2 << endl;
  return 0;
}


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

//KMP法
//検索したい文字列をmakekmpに食わせてから
//kmpsearchを呼ぶ
//*
#define KMPTYPE char
int*makekmp(KMPTYPE*t,int tlen){
	int*tt=calloc(tlen+1,sizeof(int));
	int len=0;
	tt[0]=-1;
	for(int pos=1;pos<tlen;pos++,len++){
		if(t[pos]==t[len]){
			//同じなのに失敗したら、失敗
			tt[pos]=tt[len];
		}
		else{
			//違うとき失敗したら、そこからチェック
			tt[pos]=len;
			//一致するところまで戻る
			while(len>=0&&t[pos]!=t[len])len=tt[len];
		}
	}
	tt[tlen]=len;
	return tt;
}
int kmpsearch(KMPTYPE*s,int slen,KMPTYPE*t,int tlen,int*table){
	//sの中からtを探す
	int k=0;
	for(int j=0;j<slen;){
		if(s[j]==t[k]){
			j++,k++;
			if(k==tlen){
				printf("%d\n",j-k);
				//最後まで行ったら、最後で失敗扱い
				k=table[k];
			}
		}else{
			//失敗
			k=table[k];
			if(k==-1)j++,k++;//1文字目
		}
	}
}
#undef KMPTYPE
//*/

char s[1000010],t[10010];
int main(){
	scanf("%s%s",s,t);
	int slen=strlen(s);
	int tlen=strlen(t);
	kmpsearch(s,slen,t,tlen,makekmp(t,tlen));
}


Measured memory_bytes: 2876
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  int res = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x >= k) ++res;
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);

int n, x;
int ans = 0;

void ugrid(int a, int b)
{
  if(a % b == 0){
    ans += b * (a / b * 2 - 1);
  }
  else{
    ans += b * (a / b * 2);
    ugrid(b, a % b);
  }
}

signed main()
{
  cin >> n >> x;
  ans += n;

  ugrid(max(x, n - x), min(x, n - x));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    long n,m;
    cin >> n;
    long t[n];
    F(i,0,n) cin >> t[i];
    cin >> m;
    long p[m],x[m];
    F(i,0,m) cin >> p[i] >> x[i];
    F(i,0,m){
        long ans=0;
        F(j,0,n){
            if(p[i]-1==j) ans+=x[i];
            else ans += t[j];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define MAX 40010
using namespace std;

typedef pair<int,int> pii;

int p[MAX];
int n,h,w,ans=0;
int x[MAX],y[MAX];
bool l[MAX]={},r[MAX]={},u[MAX]={},d[MAX]={};

void check(int a,int b){
  u[a]|=u[b];
  u[b]|=u[a];
  l[a]|=l[b];
  l[b]|=l[a];
  d[a]|=d[b];
  d[b]|=d[a];
  r[a]|=r[b];
  r[b]|=r[a];
}

int find(int a){
  if(p[a]==a)return a;
  int pa=find(p[a]);
  p[a]=pa;
  return pa;
}

void unite(int a,int b){
  int pa=find(a),pb=find(b);
  p[pa]=pb;
}

bool same(int a,int b){
  return find(a)==find(b);
}

int main()
{

  vector<pii> a,b;

  cin>>n>>w>>h;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    a.push_back(mp(x[i],i));
    b.push_back(mp(y[i],i));
    if(y[i]==1)d[i]=true;
    if(x[i]==1)l[i]=true;
    if(y[i]==h)u[i]=true;
    if(x[i]==w)r[i]=true;
  }

  for(int i=0;i<MAX;i++)p[i]=i;

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  for(int i=1;i<n;i++){
    if(a[i-1].f==a[i].f && !same(a[i-1].s,a[i].s)){
      unite(a[i-1].s,a[i].s);
      ans++;
    }
    if(b[i-1].f==b[i].f && !same(b[i-1].s,b[i].s)){
      unite(b[i-1].s,b[i].s);
      ans++;
    }
  }

  if(ans!=n-1){
    for(int i=0;i<n;i++)check(find(i),i);
    int sum1=0,sum2=0,sum3=0,sum4=0;
    for(int i=0;i<n;i++)if(p[i]==i)sum1++;
    sum1=(sum1*2-1);
    sum2=sum3=sum4=sum1;
    for(int i=0;i<n;i++){
      if(p[i]==i && l[i])sum1--;
      if(p[i]==i && u[i])sum2--;
      if(p[i]==i && r[i])sum3--;
      if(p[i]==i && d[i])sum4--;
    }
    ans+=min(min(sum1,sum2),min(sum3,sum4));
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

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

int main()
{
    int r, d, x0;
    cin >> r >> d >> x0;
    for (int i = 2001; i <= 2010; i++) {
        int x = r * x0 - d;
        cout << x << endl;
        x0 = x;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int b[] = new int[n+1];
        b[0] = 114514; b[n] = 114514;
        
        for(int i=1; i<n; i++) 
        	b[i] = Integer.parseInt(sc.next());
        int ans = 0;
        for(int i=0; i<n; i++)
            ans += (Math.min(b[i],b[i+1]));
        System.out.println(ans);
    }
}

Measured memory_bytes: 26984
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int color[100000];
int memo[100000][11];
vector<vector<int> > G;

int dfs(int v, int d, int c) {
    if (memo[v][d]) return memo[v][d];
    if (d == 0) {
        return memo[v][d] = color[v] = c;
    }
    for (int i = 0; i < G[v].size(); i++) {
        dfs(G[v][i], d - 1, c);
    }
    return memo[v][d] = dfs(v, d - 1, c);
}

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        G.push_back(vector<int>());
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> V, D, C;
    for (int i = 0; i < Q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        v--;
        V.push_back(v);
        D.push_back(d);
        C.push_back(c);
    }

    for (int i = Q - 1; i >= 0; i--) {
        dfs(V[i], D[i], C[i]);
    }

    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 13552
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false


signed main(void){
    int N,M;
    int A;
    cin >> N >> M;
    REP(i,M){
        cin >> A;
        N-=A;
    }
    if(N<0){
        cout << -1 << endl;
    }else{
        cout << N << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct Page{
  string name;
  vector<int> bx;
  vector<int> by;
  vector<int> ex;
  vector<int> ey;
  vector<string> to;
  Page(string n){
    name = n;
  }
  void add(int x1, int y1, int x2, int y2, string s){
    bx.push_back(x1);
    by.push_back(y1);
    ex.push_back(x2);
    ey.push_back(y2);
    to.push_back(s);
  }
  string link(int x, int y){
    REP(i,bx.size()){
      if(bx[i] <= x && x <= ex[i] && by[i] <= y && y <= ey[i]){
        return to[i];
      }
    }
    return "";
  }
};


int main(){
  int N;
  while(cin>>N, N){
    int W,H; cin>>W>>H;
    vector<Page> pages;
    map<string, int> id;
    REP(i,N){
      string s; int n;
      cin>>s>>n;
      id[s] = i;
      Page p(s);
      while(n--){
        int a,b,c,d; string nm;
        cin>>a>>b>>c>>d>>nm;
        p.add(a,b,c,d,nm);
      }
      pages.push_back(p);
    }
    int O; cin>>O;
    vector<Page> bf;
    bf.push_back(pages[0]);
    int p = 0;
    while(O--){
      string ope; cin>>ope;
      int x,y;
      if(ope == "show"){
        cout<<bf[p].name<<endl;
      }
      if(ope == "forward"){
        if(p + 1 < bf.size()) p += 1;
      }
      if(ope == "back"){
        if(p - 1 >= 0) p -= 1;
      }
      if(ope == "click"){
        cin>>x>>y;
        string linkname = bf[p].link(x,y);
        int toidx = -1;
        if(id.count(linkname)) toidx = id[linkname];
        if(toidx != -1) {
          Page nextpage = pages[toidx];
          bf.erase(bf.begin() + p + 1, bf.end());
          bf.push_back(nextpage);
          p++;
        }
      }
    }
  }
  return 0;
}

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

int main(){
  constexpr int Nmax= 100;
  int N;
  cin >> N;

  vector<int> ans(N+1);
  for(int x=1; x<Nmax; x++){
    for(int y=1; y<Nmax; y++){
      for(int z=1; z<Nmax; z++){
        int val= x*x+ y*y+ z*z+ x*y+ y*z+ z*x;
        if(val <= N){
          ans.at(val)++;
        }
      }
    }
  }
  
  for(int val=1; val<=N; val++){
    cout << ans.at(val) << endl;
  }
}

Measured memory_bytes: 3524
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]

total = 0
for i in range(n-1):
    for j in range(i+1,n):
        flg = True
        for x in range(n):
            if x == i or x == j:
                continue
            if a[i][j] > a[i][x] + a[j][x]:
                print(-1)
                exit()
            elif a[i][j] == a[i][x] + a[j][x]:
                flg = False
                break
        if flg:
            total += a[i][j]
            
print(total)

Measured memory_bytes: 74752
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = new int[n];
        for(int i = 0; i < n; i++){
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] T = new int[q];
        for(int i = 0; i < q; i++){
            T[i] = sc.nextInt();
        }
        Arrays.sort(T);
        int Sum = 0;
        for(int i = 0; i < q; i++){
            for(int j = 0; j < n; j++){
                if(S[j] == T[i]){
                    Sum++;
                    break;
                }else if(S[j] > T[i]){
                    break;
                }
            }
        }
        System.out.println(Sum);
        sc.close();
    }
}


Measured memory_bytes: 68380
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b == c + d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}

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

int main()
{
	int n, d;
	cin >> n >> d;

	//2d+1本
	//q=n/(2d+1)
	//n=q(2d+1)+r
	int member;
	member = n / (2 * d + 1);
	if (n % (2 * d + 1))member++;
	cout << member << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string a,b;
    cin >> a >> b;
    bool ans = true;
    for ( int i = 0; i < 3; i++ ) {
        if ( a[i] != b[2-i] ) { ans = false; break; }
    }
    
    cout << ( ans ? "YES" : "NO" ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P u){
 Q[tail]=u;
  if(tail+1==LEN){
      tail=0;
  } 
  else{  tail++;
  }
}

P dequeue(){
  P x;
  x=Q[head];
  if(head+1==LEN){
      head=0;
  } 
  else{  
      head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    elaps+=q;
    u=dequeue();
    u.t-=q;
    if(u.t<=0){
      elaps+=u.t;
      printf("%s %d\n",u.name,elaps);
    }
    else{ 
         enqueue(u);
    }
  }
  return 0;
}



Measured memory_bytes: 11868
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int k, pos;
	cin>>k>>pos;
	for(int i=max(-1000000,pos-k+1);i<=min(1000000,pos+k-1);i++)
		cout<<i<<" ";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s=="ABC"){
    cout << "ARC" << endl;
    return 0;
  }
  cout << "ABC" << endl;

  return 0;
}


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

int main(){
	int n;
	int s;
	int s_non10_min = INT_MAX;
	int sum = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		sum += s;
		if(s % 10 && s < s_non10_min) s_non10_min = s;
	}
	if(sum % 10 == 0){
		if(s_non10_min != INT_MAX) {
			sum -= s_non10_min;
		} else {
			sum = 0;
		}
	}
	cout << sum;
	return 0;
}



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

int main(){
  int n , l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  
  sort(s.begin(), s.end());
  
  for(int i = 0; i < n; i++){
    cout << s[i];
  }
  
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])


Measured memory_bytes: 7852
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
    int n[6];
    int Dice_sample[6][4] = {{5,3,2,4},{1,3,6,4},{1,5,6,2},
                            {1,2,6,5},{1,4,6,3},{2,3,5,4}};
    int q;
    int a,b;
    int R[25];
    int x,y;
    


    for(int i = 0; i < 6; i++){
        scanf("%d", &n[i]);
    }
    scanf("%d", &q);

    for(int j = 0; j < q; j++){
        scanf("%d %d", &a, &b);

        for(int k = 0; k < 4; k++){
            int temp = n[3];
            n[3] = n[5];
            n[5] = n[2];
            n[2] = n[0];
            n[0] = temp;
            if(n[0] == a){
                break;
            }
        }
        for(int l = 0; l < 4; l++){
            int temp = n[5];
            n[5] = n[4];
            n[4] = n[0];
            n[0] = n[1];
            n[1] = temp;
            if(n[0] == a){
                break;
            }
        }
        for(int z = 0; z < 4; z++){
            int temp = n[1];
            n[1] = n[2];
            n[2] = n[4];
            n[4] = n[3];
            n[3] = temp;
            if(n[1] == b){
                break;
            }
        }

        printf("%d\n", n[2]);

    }
    return (0);
}



Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n; cin >> n;
	int ans = n + 10;
	for (int i = 1; i <= sqrt(n); i++) if (n%i == 0)ans = min(ans, i + n / i - 2);
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll         	pair<ll,ll>
#define vec     		vector<ll>
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a,mod-2);
}

void solve()
{
	int n;
	
	string s;
	
	cin>>n>>s;
	
	s = '?' + s;
	
	int ans = 0;
	
	for(int i=1;i<=n;i++)
	{
		for(int j=i+2;j<=n;j++)
		{
			if((j-i)%2 == 0)
			{
				if(s[i] != s[j]  and s[(j+i)/2] != s[i] and s[(j+i)/2] != s[j])
				{
					ans++;
				}
			}
		}
	}
	
	int tot = 0;
	
	ll dp1[6];
	ll dp2[3];
	ll dp3[6];
	
	fill(dp1,0);
	fill(dp2,0);
	fill(dp3,0);
	
	for(int i=1;i<=n;i++)
	{
		if(s[i] == 'R')	
		{
			dp1[2] += dp3[2];
			dp1[5] += dp3[3];
			
			dp3[1] += dp2[1];
			dp3[5] += dp2[2];
			
			dp2[0]++;
		}
		if(s[i] == 'G')
		{
			dp1[0] += dp3[4];
			dp1[4] += dp3[5];
			
			dp3[0] += dp2[0];
			dp3[3] += dp2[2];
			
			dp2[1]++;
		}
		if(s[i] == 'B')
		{
			dp1[1] += dp3[0];
			dp1[3] += dp3[1];
			
			dp3[2] += dp2[1];
			dp3[4] += dp2[0];
			
			dp2[2]++;
		}
	}
	
	for(int i=0;i<6;i++)
	{
		tot += dp1[i];
	}
	
	cout<<tot-ans;
}

signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  // bool is useful for MST 
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
  int n, m, k; cin >> n >> m >> k;
  UnionFind uf(n);  
  vi deg(n);
  rep(i,m) {
    int a,b; cin >> a >>b;
    a--; b--;
    uf.unite(a,b);
    deg[a]++;
    deg[b]++;
  }
  vvi to(n);
  rep(i,k) {
    int c,d; cin >> c >> d;
    c--; d--;
    to[c].push_back(d);
    to[d].push_back(c);
  }
  rep(i, n) {
    int ans = uf.size(i) - 1 - deg[i];
    for (int x: to[i]) {
      if (uf.same(x, i)) ans--;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2) {
        int cnt = 0;
        for(int j = 2; j < i; j++) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 6) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> as(n);
  for(int i = 0; i < n; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());
  ll mxs = as.back();
  sort(as.begin(), as.end() - 1,
       [&mxs](const auto& a, const auto& b) { return abs(a * 2 - mxs) < abs(b * 2 - mxs); });
  /*
  for(auto a : as) {
    cout << a << endl;
  }
  */
  cout << mxs << " " << as[0] << endl;
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
L = []
for i in range(0, 87):
    if (i == 0):
        L.append(2)
    if(i == 1):
        L.append(1)
    elif (i >= 2):
        L.append(L[i - 1] + L[i - 2])

print(L[N])


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

using namespace std;

#define N 20

int v[N + 1];
int c[N + 1];

int main(){
	int ans, n, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		scanf("%d", v + i);
	}

	for (i = 1; i <= n; i++){
		scanf("%d", c + i);
	}

	ans = 0;

	for (i = 1; i <= n; i++){
		if (v[i] > c[i]){
			ans += v[i] - c[i];
		}
	}

	printf("%d\n", ans);

	return 0;
}

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

#define Size 1000000

inline int readInt()
{
	register int x,c;static char buf[Size],*ss,*tt;
	#define pick()((ss==tt)?(tt=buf+fread(ss=buf,1,Size,stdin),(ss==tt)?-1:*ss++):*ss++)
	while(!isdigit(c=pick()));
	for(x=-48+c;isdigit(c=pick());x=x*10+c-48);
	return x;
	#undef pick
}	
inline void smin(long long &d,long long x) {(d>x)?d=x:0;}
const long long inf=(~0ull>>1);
const int N=200010;
int q[N];
bool inq[N];
long long a[N];
struct edge{
	int to,w;edge*nxt;
}g[N],*head[N],*NewEdge;
int main()
{
	int h,w,n;
	h=readInt(),w=readInt(),n=readInt();
	NewEdge=g;
	for(int i=0;i<n;++i)
	{
		int x=readInt(),y=readInt(),z=readInt();
		--x,--y;
		*(++NewEdge)=(edge){h+y,z,head[x]};head[x]=NewEdge;
		*(++NewEdge)=(edge){x,z,head[h+y]};head[h+y]=NewEdge;
	}
	for(int i=0,l=h+w;i<l;++i)
	{
		if(!inq[i])
		{
			register edge*it;
			register int fr(0),tl(0);
			a[i]=0;
			q[++tl]=i;
			inq[i]=true;
			while(fr^tl)
			{
				int u=q[++fr];
				for(it=head[u];it;it=it->nxt)
				{
					int r=it->to,v=it->w;
					if(inq[r])
					{
						if(a[u]+a[r]!=v) return puts("No"),0;
						continue;
					}
					q[++tl]=r;
					inq[r]=true;
					a[r]=v-a[u];
				}
			}
			long long m1=inf,m2=inf;
			while(tl) (q[tl]<h)?smin(m1,a[q[tl--]]):smin(m2,a[q[tl--]]);
			if(m1+m2<0) return puts("No"),0;
		}
	}
	return puts("Yes"),0;
}

Measured memory_bytes: 8448
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream ps = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] score = new int[n];
        int[] maxJ = new int[n];
        boolean[] b = new boolean[20];
        
        for (int i = 0; i < n; i++) {
            if (i != 0 && score[i-1] > 1) {
                if (maxJ[i-1] == n) {
                    score[i] = score[i-1] -1;
                    maxJ[i] = maxJ[i-1];
                    continue;
                }
                int x = a[i-1] & a[maxJ[i-1]];
                if (x == 0) {
                    score[i] = score[i-1] -1;
                    maxJ[i] = maxJ[i-1];
                    continue;
                }
            }
            fill(b, a[i]);
            score[i]++;
            
            
            for (int j = i+1; j < n; j++) {
                int aj = a[j];
                if (fill(b, aj)) {
                    score[i]++;
                    if (j == n-1) {
                        maxJ[i] = n;
                    }
                } else {
                    maxJ[i] = j;
                    break;
                }
            }
            b = new boolean[20];
            
        }
        long total = 0;
        for (int i = 0; i < n; i++) {
            total += score[i];
        }
        ps.println(total);
    }
    
    public static boolean fill(boolean[] b, int n) {
        int x = b.length - 1;
        while (n > 0) {
            int a = n & 1;
            if (a == 1) {
                if (!b[x]) {
                    b[x] = true;
                } else {
                    return false;
                }
            }
            n = n >> 1;
            x--;
        }
        return true;
    }
}


Measured memory_bytes: 91596
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	A := ReadInts(N)
	max := int(3 * 1e5)
	seg := MakeSegTree(max + 1)
	for _, ai := range A {
		l := Max(0, ai-K)
		r := Min(max, ai+K)
		v := seg.Query(l, r+1)
		seg.Update(ai, v+1)
	}
	fmt.Println(seg.Query(0, max+1))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

// Segment Tree for Range Maximum Query (RMQ)
type SegTree []int

func MakeSegTree(n_ int) SegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	return make([]int, n*2)
}
func (t SegTree) Update(i, x int) {
	i += len(t) >> 1
	t[i] = x
	for i > 1 {
		i >>= 1
		t[i] = Max(t[i*2], t[i*2+1])
	}
}
func (t SegTree) Query(a, b int) int {
	return t.queryRecur(a, b, 1, 0, len(t)>>1)
}
func (t SegTree) queryRecur(a, b, k, l, r int) int {
	if b <= l || r <= a {
		return 0
	}
	if a <= l && r <= b {
		return t[k]
	}
	return Max(
		t.queryRecur(a, b, k*2, l, (l+r)>>1),
		t.queryRecur(a, b, k*2+1, (l+r)>>1, r),
	)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


Measured memory_bytes: 17380
a, b = map(int,input().split())
li = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

if li.index(a) == li.index(b):
    print("Draw")
elif li.index(a) > li.index(b):
    print("Alice")
else:
    print("Bob")

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

using namespace std;

#define MAX_N 1000
#define MAX_K 3000

typedef long long ll;

typedef struct {
  ll value;
  int ia;
  int ib;
  int ic;
} cake;

typedef struct cake_idx_t {
  int ia;
  int ib;
  int ic;
  bool operator <(const cake_idx_t& rhs) const {
    return tie(ia, ib, ic) < tie(rhs.ia, rhs.ib, rhs.ic);
  }
} cake_idx;

bool comp(cake c1, cake c2) { return c1.value < c2.value; }

int X, Y, Z, K;
ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];
priority_queue<
  cake,
  vector<cake>,
  function<bool(cake, cake)>
> pq(comp);

//「狭義の弱順序」でないといけないらしい
//ここではまった（等しいではない）
//微妙に合わない... (重複の判定ができない？）
//countが効かなそう
map<cake_idx, bool> pq_flag;

int main() {
  cin >> X >> Y >> Z >> K;

  for(int i=0; i<X; i++) cin >> a[i]; sort(a, a + X, greater<ll>());
  for(int i=0; i<Y; i++) cin >> b[i]; sort(b, b + Y, greater<ll>());
  for(int i=0; i<Z; i++) cin >> c[i]; sort(c, c + Z, greater<ll>());

  //キューに入れる
  pq.push({a[0] + b[0] + c[0], 0, 0, 0});
  pq_flag.insert(make_pair(cake_idx {0, 0, 0}, true));
  //  cout << pq_flag.count(cake_idx {0,0,0}) << endl;
  //  cout << pq_flag.at(cake_idx {0,0,0}) << endl;

  for(int i=0; i<K; i++) {
    cake ck = pq.top();
    pq.pop();
    if(ck.ia + 1 < X && pq_flag.count(cake_idx {ck.ia + 1, ck.ib, ck.ic}) == 0) {
      pq.push({a[ck.ia + 1] + b[ck.ib] + c[ck.ic], ck.ia + 1, ck.ib, ck.ic});
      pq_flag.insert(make_pair(cake_idx {ck.ia + 1, ck.ib, ck.ic}, true));
    }
    if(ck.ib + 1 < Y && pq_flag.count(cake_idx {ck.ia, ck.ib + 1, ck.ic}) == 0) {
      pq.push({a[ck.ia] + b[ck.ib + 1] + c[ck.ic], ck.ia, ck.ib + 1, ck.ic});
      pq_flag.insert(make_pair(cake_idx {ck.ia, ck.ib + 1, ck.ic}, true));
    }
    if(ck.ic + 1 < Z && pq_flag.count(cake_idx {ck.ia, ck.ib, ck.ic + 1}) == 0) {
      pq.push({a[ck.ia] + b[ck.ib] + c[ck.ic + 1], ck.ia, ck.ib, ck.ic + 1});
      pq_flag.insert(make_pair(cake_idx {ck.ia, ck.ib, ck.ic + 1}, true));
    }

    cout << ck.value << endl;

    if(pq.empty()) break;
  }
    
  return 0;
}

  


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m,a,b;
  cin>>n>>m>>a>>b;
  vector<Int> d(n);
  for(Int i=0;i<n;i++) cin>>d[i];

  stack<Int> que;
  for(Int i=0;i<n;i++){
    if(d[i]>=a) que.emplace(i);
    else break;
  }
  
  if(n-(Int)que.size()>=m){
    cout<<que.size()<<endl;
    return 0;
  }
  
  while(!que.empty()){
    if(d[que.top()]<=b){
      que.pop();
      continue;
    }
    break;
  }
  
  cout<<que.size()<<endl;
  return 0;
}



Measured memory_bytes: 3136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp41 {
    class Program {
        static void Main(string[] args) {
            int a = int.Parse(Console.ReadLine());

            Console.WriteLine(a + a * a + a * a * a);
        }
    }
}


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

int main(){
    int n,d,x[20][20],ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            if(sqrt(sum)==(int)sqrt(sum)) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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 <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

#endif


ll  n;
vector<ll> c, s, f;


void Solve(ll start, ll& ans)
{
	ans = 0;
	rep(i, start, n-1)
	{
		if (ans < s[i])
			ans = s[i];
		else if ((ans - s[i]) % f[i] != 0)
			ans += (f[i] - (ans - s[i]) % f[i]);
		ans += c[i];
	}
}


int main(void)
{
	cin >> n;
	c.resize(n);
	s.resize(n);
	f.resize(n);
	rep(i, 0, n-1)
		cin >> c[i] >> s[i] >> f[i];

	ll ans = 0;
	rep(i, 0, n)
	{
		Solve(i, ans);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	private static StringBuffer map[];
	private static int count;
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt(), m = sc.nextInt();
			if (n == 0 && m == 0) break;
			map = new StringBuffer[m];
			count = 0;
			int x = 0, y = 0;
			for (int i = 0; i < m; i++)
			{
				String str = sc.next();
				if (str.indexOf('@') != -1)
				{
					x = str.indexOf('@');
					y = i;
				}
				map[i] = new StringBuffer(str);
			}
			walk(x, y);
			System.out.println(count);
		}
	}
	private static void walk(int x, int y)
	{
		count++;
		map[y].setCharAt(x, '#');
		try{
			if (map[y-1].charAt(x) == '.') walk(x, y - 1);
		}catch (IndexOutOfBoundsException e){}
		try{
			if (map[y+1].charAt(x) == '.') walk(x, y + 1);
		}catch (IndexOutOfBoundsException e){}
		try{
			if (map[y].charAt(x+1) == '.') walk(x + 1, y);
		}catch (IndexOutOfBoundsException e){}
		try{
			if (map[y].charAt(x-1) == '.') walk(x - 1, y);
		}catch (IndexOutOfBoundsException e){}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<cmath>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
ll factorial(ll n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}


int main() {
	double n,sum=0;
	cin >> n;
	vector<ll>x(n), y(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (ll i = 0; i < n-1; i++) {
		for (ll j = i + 1; j < n; j++) {
			sum +=sqrt(pow(x[i] - x[j], 2)+pow(y[i]-y[j],2));
		}
	}
	printf("%.9f\n", sum*2*factorial(n-1) / factorial(n));

}


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

#define MOD 1000000007LL

using lint = long long int;
using pii = std::pair<int, int>;

using std::max;
using std::min;

lint facto(lint N) {
	lint ret = 1;
	for (int i = 1; i <= N; i++) {
		ret *= i;
		ret %= MOD;
	}
	return ret;
}

int main(void) {
	lint N, M;
	scanf("%lld %lld", &N, &M);

	if (max(N, M) - min(N, M) > 1) {
		printf("0");
		return 0;
	}
	
	if (N == M) {
		printf("%lld", (facto(N) * facto(M) * 2) % MOD);
	}
	else {
		printf("%lld", (facto(N) * facto(M)) % MOD);
	}

	return 0;
}

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

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

lint gcd(lint a, lint b)
{
    if(a==b){
        return a;
    }
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

lint lcm(lint a, lint b)
{
    if (a == b)
    {
        return a;
    }
    lint big = max(a, b), small = min(a, b);
    if (big % small == 0)
        return big;
    return (a / gcd(a, b))*b;
}

int main()
{
    lint n;
    cin >> n;
    //vector<lint> t(n);
    lint ans;
    lint t;
    cin >> ans;
    REP(i, n-1) {
        cin >> t;
        ans = lcm(t, ans);
        //cout << ans << "\n";
    }
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int maxn=5e5+1212;

int n,m1,m2;
int edgenum;
bool vis[maxn];
int head[maxn],Next[maxn],b[maxn],V[maxn];
int num[maxn];
vector <int> human[maxn],vv;
bool book[maxn];
void add(int u,int v)
{
    V[++edgenum]=v;
    Next[edgenum]=head[u];
    head[u]=edgenum;
}

void DFS(int u)
{
    vis[u]=true;
    int pos=b[u];
    if(book[pos]==false) vv.push_back(pos);
    human[pos].push_back(u);
    for(int i=head[u];i!=-1;i=Next[i])
    {
        int v=V[i];
        if(vis[v]==false) DFS(v);
    }
}

int f(int x)
{
    if(b[x]==x) return x;
    else return b[x]=f(b[x]);
}
int main()
{
    int u,v;
    while(scanf("%d %d %d",&n,&m1,&m2)!=EOF)
    {
        for(int i=1;i<=n;i++) b[i]=i;
        for(int i=1;i<=m1;i++)
        {
            scanf("%d %d",&u,&v);
            int t1=f(u),t2=f(v);
            b[t2]=t1;
        }
        for(int i=1;i<=n;i++) b[i]=f(i);
        memset(vis,false,sizeof(vis));
        memset(head,-1,sizeof(head));
        memset(book,false,sizeof(book));
        memset(num,0,sizeof(num));
        edgenum=0;
        for(int i=1;i<=m2;i++)
        {
            scanf("%d %d",&u,&v);
            add(u,v);
            add(v,u);
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==false)
            {
                DFS(i);
                for(int j=0;j<(int)vv.size();j++)
                {
                    int pos=vv[j];
                    for(int s=0;s<(int)human[pos].size();s++)
                    {
                        int q=human[pos][s];
                        num[q]+=human[pos].size();
                    }
                    human[pos].clear();
                }
                vv.clear();
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(i==n) printf("%d\n",num[i]);
            else printf("%d ",num[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 29184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String result ;
		int count = 0;

		while (true) {
			String str = br.readLine();
			if (str.equals("-")) {
				break;
			}

			String res = br.readLine();
			count = Integer.parseInt(res);
			int[] shuffle = new int[count];
			for(int i =0; i < count; i++){
				String shuffler = br.readLine();
				shuffle[i] = Integer.parseInt(shuffler);
				result = str.substring(0,shuffle[i]);
				
				str += result;
				str = str.substring(shuffle[i]);
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 24424