akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	int N;
	cin>>N;
	print((N-2)*180);
	return 0;
}


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

using namespace std;

int main(void){

	int l[10],v[2],lw;
	double x,ln;

	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1])!=EOF){
		lw=0;
		for(int i=0;i<10;i++) lw+=l[i];
		x=(double)(lw)/(v[0]+v[1]);
		ln=v[0]*x;
		for(int i=0;i<10;i++){
			ln-=l[i];
			if(ln<=0){
				cout<<i+1<<endl;
				break;
			}
		}
	}

return 0;

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<double> v(N);
    rep(i, N) { cin >> v[i]; }
    sort(v.begin(), v.end());
    for (int i = 1; i < N; i++) {
        v[i] = (v[i] + v[i - 1]) / 2.0;
    }
    cout << v[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())
A = input()

R = [0 for _ in range(N + 5)]
G = [0 for _ in range(N + 5)]
B = [0 for _ in range(N + 5)]

for i in range(N):
    if(i != 0):
        R[i] = R[i - 1]
        G[i] = G[i - 1]
        B[i] = B[i - 1]
    if (A[i] == 'R'):
        R[i] += 1
    elif (A[i] == 'G'):
        G[i] += 1
    elif (A[i] == 'B'):
        B[i] += 1
        
ans = 0
for i in range(1, N):
    if A[i] == 'R':
       ans += G[i - 1] * (B[N - 1] - B[i]) 
       ans += B[i - 1] * (G[N - 1] - G[i]) 
    if A[i] == 'G':
       ans += R[i - 1] * (B[N - 1] - B[i]) 
       ans += B[i - 1] * (R[N - 1] - R[i]) 
    if A[i] == 'B':
       ans += G[i - 1] * (R[N - 1] - R[i]) 
       ans += R[i - 1] * (G[N - 1] - G[i])
    # print(i, ans, end = "")
    for j in range(1, min([N - i - 1, i]) + 1):
        if A[i - j] != A[i] and A[i] != A[i + j] and A[i - j] != A[i + j]:
            ans -= 1
    #print(ans)

print(ans)

Measured memory_bytes: 9400
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int H = scanner.nextInt();
    int W = scanner.nextInt();

    System.out.println((N - H + 1) * (N - W + 1));
  }
}


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


int main(){
  int N;
  cin >> N;
  vector<tuple<string , int , int>> board(N);

  for(int i=0 ;i<N ; i++){
    string S;
    int a;
    cin >> S >> a;
    a *= -1;
    board.at(i) = make_tuple(S , a , i+1);
  }
  sort (board.begin() , board.end());

  for(int i=0; i<N ; i++){
    string L;
    int b , number;
    tie(L , b , number) = board.at(i);
    
    cout << number << endl;
    
  }

  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
  int i,n,k,sum=0;
  int dis;
  int x[100];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    dis=fmin(x[i],abs(x[i]-k));
    sum+=dis;
  }
  printf("%d",sum*2);
  return 0;
}

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

int main(){
    int n,m,a,b;
    cin >> n >> m;
    vector<vector <int>> r(n+1);
    vector<int> answer(n+1);
    for(int i = 0;i<m;i++){
        cin >> a >> b;
        r.at(a).push_back(b);
        r.at(b).push_back(a);
    }
    vector<bool> checked(n+1,false);
    queue<int> q;
    q.push(1);
    checked.at(1) = true;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(int i:r.at(t)){
            if(!checked.at(i)){
                answer.at(i) = t;
                checked.at(i) = true;
                q.push(i);
            }
            
        }
    }
    cout << "Yes" << endl;
    for(int i = 2;i<=n;i++){
        cout << answer.at(i) << endl;
    }
}


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

int main(){
	while(1){
		long a, b;
		long x, y, z;
		
		scanf(" %ld %ld", &a, &b);
		if(a==0) break;
		
		long r=b-a;
		
		x=r/1000;
		r-=x*1000;
		y=r/500;
		r-=y*500;
		z=r/100;
		
		printf("%ld %ld %ld\n", z, y, x);
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, M, K;
int D[20];
int v[105][105];
int inv[105];
int dist[1<<17];

bool chmin(int &a, int b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    //cout.precision(10);
    cin >> N >> M >> K;
    for(int i = 0; i < (1 << M); i++) dist[i] = INF;
    for(int i = 0; i <= N; i++) inv[i] = -1;
    for(int i = 0; i < M; i++) {
        cin >> D[i];
        inv[D[i]] = i;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= K; j++) {
            cin >> v[i][j];
        }
    }
    dist[(1 << M) - 1] = 0;
    queue<int> que;
    que.push((1 << M) - 1);
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        for(int j = 1; j <= K; j++) {
            int newbit = 0;
            for(int i = 0; i < M; i++) {
                if(!(now & (1 << i))) continue;
                int next = v[D[i]][j];
                if(inv[next] == -1) continue;
                newbit |= (1 << inv[next]);
            }
            if(chmin(dist[newbit], dist[now] + 1)) que.push(newbit);
        }
    }
    cout << dist[0] << endl;
    return 0;
}



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

int main( void )
{
	int n, k;
	while ( cin >> n >> k && n > 0 && k > 0 )
	{
		vector <int> a( n+1, 0 );
		vector <int> dp( n+1, 0 );

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

		for ( int i = 1; i < n+1; i++ )
			dp[i] = dp[i-1] + a[i];

		int maxv = 0;
		for ( int i = 0; i < n+1-k; i++ )
		{
			maxv = max( maxv, dp[i+k] - dp[i] );
		}

		cout << maxv << endl;

	}
}

Measured memory_bytes: 1700
#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<600)
        cout<<"8\n";
    else if(n<800)
        cout<<"7\n";
    else if(n<1000)
        cout<<"6\n";
    else if(n<1200)
        cout<<"5\n";
    else if(n<1400)
        cout<<"4\n";
    else if(n<1600)
        cout<<"3\n";
    else if(n<1800)
        cout<<"2\n";
    else if(n<2000)
        cout<<"1\n";
}

Measured memory_bytes: 3512
#D問題
N=int(input())
S=str(input())
Slist=list(S)
Left=[] #"("
Right=[] #")"
for i in range(N):
    if Slist[i] == "(":
        Left.append(i)
    else:
        if len(Left) == 0:
            Right.append(i)
        else:
            del Left[0]
Llen=len(Left)
Rlen=len(Right)
for i in range(Llen):
    Slist.insert(2*N,")")    
for i in range(Rlen):
    Slist.insert(0,"(")
ans="".join(Slist)
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;
lli A[200005];
lli B[200005];

int main(void){
	scanf("%d",&n);
	rep(i,n)scanf("%lld",&A[i]);
	rep(i,n)scanf("%lld",&B[i]);
	
	lli b=1;
	lli ans=0;
	while(b<(1LL<<29)){
		vector<lli> ps[2];
		rep(i,n){
			lli r=B[i]&(b-1);
			ps[(B[i]&b)?1:0].push_back(r);
		}
		sort(ps[0].begin(),ps[0].end());
		sort(ps[1].begin(),ps[1].end());
		
		lli t=0;
		rep(i,n){
			lli r=A[i]&(b-1);
			int d=(A[i]&b)?1:0;
			d = 1-d;
			//printf("%d %d\n",ps[0].size(),ps[1].size());
			t += mimunum(ps[d],b-r);
			t += (ps[1-d].size()-mimunum(ps[1-d],b-r));
			//printf("%lld %lld : %d\n",b,A[i],t);
		}
		
		if(t%2)ans += b;
		b *= 2;
	}
	
	
	printf("%lld\n",ans);
	
	return 0;
}






Measured memory_bytes: 6960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD ((ll)1000000007)
ll n,m;
ll ans;
inline ll solve(ll a,ll b);
int main(){
    cin>>n>>m;
    ans=solve(n,m);
    cout<<ans<<endl;
    return 0;
}

inline ll solve(ll a,ll b){
        ll res=1L;
            ll now=max(a,b);
            ll now2=min(a,b);
            while(1){
                if(now==1)break;
                ll temp=((now%MOD)*(now2%MOD))%MOD;
                res=((res%MOD)*(temp%MOD))%MOD;
                now2--;
                now--;
        }
            if(a==b)res=((res%MOD)*2)%MOD;
    return res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int ans[31]={};
int a[31],b[31];

int main() {

	int w,n;
	cin>>w;
	cin>>n;
	char c=',';
	rep(i,n)cin>>a[i]>>c>>b[i];
	for(int i=1; i<w+1; i++){
		int x=i;
		rep(j,n){
			if(x==a[j])x=b[j];
			else if(x==b[j])x=a[j];
		}
		ans[x]=i;
	}
	rep(i,w)cout<<ans[i+1]<<endl;

	return 0;
}



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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

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


int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    int H,W,N;
    cin >> H >> W >> N;

    int a[H][W];
    memset(a, 0, sizeof(a));
    int vis[H][W];
    memset(vis, -1, sizeof(vis));

    int start = 0;
    rep(r,H) {
        string t;
        cin >> t;
        rep(c,W) {
            if(t[c] == 'S')
                start = r*W + c;
            else if(t[c] == 'X')
                a[r][c] = -1;
            else if(t[c] != '.')
                a[r][c] = t[c] - '0';
        }
    }


    int ans = 0;

    REP(target,1,N+1) {
        queue<int> que;
        que.push(start);

        memset(vis, -1, sizeof(vis));
        vis[start / W][start % W] = 0;

        while (!que.empty()) {
            int t = que.front(); que.pop();
            int r = t / W;
            int c = t % W;

            if (a[r][c] == target) {
                ans += vis[r][c];
                start = r * W + c;
                break;
            }

            rep(i, 4) {
                int nr = r + dy[i];
                int nc = c + dx[i];

                if (nr < 0 || H <= nr || nc < 0 || W <= nc
                    || a[nr][nc] == -1 || vis[nr][nc] != -1)
                    continue;

                vis[nr][nc] = vis[r][c] + 1;

                //cerr << r << " " << c <<  " : " << a[r][c] <<  endl;


                que.push(nr * W + nc);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9052
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int top,S[101];
string str;


void initialize() { //初期化
  top = 0;
}

int isEmpty() { //空か確認
  return top == 0;
}

int isFull() { //オーバーしていないか確認
  return top >= 100;
}

void push(int x) { //push
  if ( isFull() )cout << "overflow" << endl;
  else {
    top++;
    S[top] = x;
  }
}

int pop() { //pop
  if ( isEmpty() ) cout << "underflow" << endl;
  else {
    top--;
    return S[top+1];
  }
}

int main() {
  
  initialize();
  
  int num1,num2;
  
  while ( cin >> str ) {
    // '+'か '-'か '*'か数字か判断
    if ( str[0] == '+') {
      num1 = pop();
      num2 = pop();
      push( num1 + num2 );
      
    }else if ( str[0] == '-' ) {
      
      num1 = pop();
      num2 = pop();
      push( num2 - num1 );
      
    }else if ( str[0] == '*' ) {
      
      num1 = pop();
      num2 = pop();
      push( num1 * num2 );
      
    } else {
      
      push(atoi(str.c_str()));
      //文字から数字に変換
      
    }
    
  }
  
  cout << pop() << endl; //答えを出力

  return 0;
}

Measured memory_bytes: 1188
/*
   Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c) (c).begin(), (c).end()
#define pii pair < ll, ll >
#define vi vector < ll >
#define vb vector < bool >
#define vvi vector < vector < ll > >
#define vvb vector < vector < bool > >
#define vpii vector < pair < ll, ll > >
#define vvpii vector < vector < pair < ll, ll > > >
#define pb push_back
#define f first
#define s second
#define mp make_pair

ll power(ll x, ll y){
    ll value = 1;
    while(y){
        if(y&1)
            value = (value * x) % 2019;
        y >>= 1;
        x = (x * x) % 2019;
    }
    return value;
}


ll solve(){
    string str;
    cin >> str;
    reverse(all(str));
        
    vi vec(str.size() + 1, 0);
    for(ll i=1; i<=str.size(); i++)
        vec[i] = (vec[i-1] + (str[i-1]-'0')*power(10, i-1)) % 2019;
    ll count[2019] = {0};
    for(ll u : vec)
        count[u]++;

    ll ans = 0;
    for(ll i=0; i<2019; i++)
        ans += count[i]*(count[i]-1)/2;
    cout << ans << endl;

    return 0;
}

int main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// auto mod int
int mod;
// const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator-=(const mint a) {
      if ((x += mod-a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}

    // bool operator==(const mint a) { return x == a.x; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll n, x;

int main() {
    cin >> n >> x >> mod;
    vector<ll> avec;
    avec.emplace_back(x);
    vector<bool> abvec(mod+1, false);
    vector<ll> amvec;
    vector<int> abivec(mod+1, -1);

    int pre = -1, last = -1;
    for(int i = 1; ; ++i) {
        if(avec[i-1] == 0) break;
        ll ai = avec[i-1]*avec[i-1];
        ai %= mod;
        if(abvec[ai]) {
            // cout << ai << endl;
            pre = abivec[ai];
            last = i-1;
            break;
        }
        abvec[ai] = true;
        amvec.emplace_back(ai);
        avec.emplace_back(ai);
        abivec[ai] = i-1;
    }

    // 止まることを確認
    int amlen = amvec.size();
    // cout << "now " << amlen << endl;
    if(amlen == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long sum = x;
    if(amvec[amlen-1] == 0) {
        for(int i = 0; i < amlen; ++i) sum += amvec[i];
    }else {
        // ループする
        for(int i = 0; i < pre; ++i) sum += amvec[i];
        ll rest = n-1-(pre);
        ll rlen = last-pre;
        ll rsum = 0;
        ll cnt = rest/rlen;
        ll rcnt = rest - rlen*cnt;
        for(int i = pre; i < last; ++i) rsum += amvec[i];
        // cout << "rsum " << rsum << endl;
        sum += rsum*cnt;
        for(int i = 0; i < rcnt; ++i) sum += amvec[pre+i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 4644
//Christmas if D=25, Christmas Eve if D=24, Christmas Eve Eve if D=23 and Christmas Eve Eve Eve if D=22.
 
#include<iostream>
#include<cstdio>
using namespace std;
long long n,nown;
long long ans;
long long sum;
int cnt=1;
long long limit;
int main()
{
	
	cin>>n;
	if(n==25)
	cout<<"Christmas"<<endl;
	if(n==24)
	cout<<"Christmas Eve"<<endl;
	if(n==23)
	cout<<"Christmas Eve Eve"<<endl;
	if(n==22)
	cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}


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

using namespace std;

double calc_radius(double l, double theta1, double theta2) {
  return l / (1 / tan(theta1 / 2) + 1 / tan(theta2 / 2) + 2);
}

double calc_distance(double x1, double y1, double x2, double y2) {
  const double dx = x2 - x1, dy = y2 - y1;
  return sqrt(dx * dx + dy * dy);
}

double calc_angle(double dx1, double dy1, double dx2, double dy2) {
  const double norm1 = sqrt(dx1 * dx1 + dy1 * dy1);
  const double norm2 = sqrt(dx2 * dx2 + dy2 * dy2);
  const double inner = dx1 * dx2 + dy1 * dy2;
  return acos(inner / (norm1 * norm2));
}

int main(int argc, char *argv[]) {
  // read inputs
  double xs[3], ys[3];
  for (int i = 0; i < 3; i++) {
    scanf("%lf %lf", &xs[i], &ys[i]);
  }

  double ls[3], ts[3];
  for (int i = 0; i < 3; i++) {
    ls[i] = calc_distance(xs[(i + 1) % 3], ys[(i + 1) % 3], xs[(i + 2) % 3],
                          ys[(i + 2) % 3]);
    ts[i] = calc_angle(xs[(i + 1) % 3] - xs[i], ys[(i + 1) % 3] - ys[i],
                       xs[(i + 2) % 3] - xs[i], ys[(i + 2) % 3] - ys[i]);
    // printf("i = %d, l = %lf, t = %lf\n", i, ls[i], ts[i]);
  }

  double rs[3], ans = 0;
  for (int i = 0; i < 3; i++) {
    rs[i] = calc_radius(ls[i], ts[(i + 1) % 3], ts[(i + 2) % 3]);
    ans = max(ans, rs[i]);
  }
  printf("%.15lf\n", ans);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int n,l,min,ans=0;
   cin>>n>>l;
   if(l<=0&&l+n-1>=0)min=0;
   else if(l+n-1<0) min=l+n-1;
   else min=l;
   rep(i,n)
     ans+=l+i;
   cout<<ans-min<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//map
int main()
{

    int a,b,c;
    int cnt = 0;
    cin >> a >> b >> c;

    for(int i = a; i <= b; ++i)
    {
        if(c % i == 0 )++cnt;
    }

    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	inp();
	return 0;
}
char s [100];
void inp(){
	scanf("%s",s);
	int l = strlen(s);
	s[l-8]='\0';
	puts(s);


}
//tmp.cc by xsthunder at Sun Oct  8 20:01:47 2017


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int N; cin >> N;
  int A[201];
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
  }
  int cnt = 0;
  bool f = true;
  while(f) {
    for ( int i = 0; i < N; i++ ) {
      if ( A[i] % 2 == 1 ) {
	f = false;
	break;
      } else {
	if(f && i == N-1) {
	  for ( int j = 0; j < N; j++ ) {
	    A[j] /= 2;
	  }
	  cnt++;
	}
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//coded by Nurstan ^_^

#define ll long long
#define pb push_back
#define mp make_pair

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

#define F first
#define S second

// fixed << setprecision
// next_permutation(a, a + n)
// set <int> :: iterator it = x.begin(); it != x.end(); it ++

using namespace std;

const ll INF = int(1e9) + 123;
const int UNF = int(1e5) * 2;

inline void boost(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}
vector <int> x;
int main(){
	boost();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n;
	cin >> n;
	ll m;
	m = n;
	int l = 0;
	
	while(m != 0) {
		x.pb(m % 10);
		m /= 10;
		l ++;
	}
	bool t = 0;
	for(int i = 0; i < x.size(); i ++) {
		if(x[i] != 9) {
			t = 1;
			break;
		}
	}
	if(t == 0) {
		cout << 9 * l;
		return 0;
	}
	else {
		ll ans = 0;
		for(int i = 1; i < l; i ++) {
			ans += 9;
		}
			t = 0;
			for(int i = x.size() - 2; i >= 0; i --) {
				if(x[i] != 9) {
					t = 1;
					break;
				}
			}
		if(t == 1) {
			cout << ans + x.back() - 1 ;
		}
		else {
			cout << ans + x.back();
		}
	}
	
	exit(0); 
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,a,b,c,d,x,y,z,o,A,B;
    cin>>n>>a>>b>>c>>d;
    z=0;
    o=0;
    x=0;
    y=0;
    while(1){
        if(n<=z){break;}
        z=a+z;
        x++;
    }
    while(1){
        if(n<=o){break;}
        o=o+c;
        y++;
    }
    A=b*x;
    B=d*y;
    if(A>=B){cout<<B<<endl;}
        else{cout<<A<<endl;}
    return 0;    
    }
    




Measured memory_bytes: 3112
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const ll INF = 1e9;


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


int main() {

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

	
	int n;
	cin >> n;
	vector<int> a(n);
	

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

	int ans = 0;
	for (int i = 1; i < n; i++)
	{
		if (a[i] > a[i - 1]) {
			ans++;
		}

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



Measured memory_bytes: 3368
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/

/*-----<Debugging Stuff>-----*/
string to_string(char s)
{   string res="'''";res[1]=s;return res; }

string to_string(string s)
{   return '"'+s+'"'; }

string to_string(const char* s)
{   return to_string((string)s); }

string to_string(bool b)
{   return (b?"true":"false"); }

template<typename A, typename B>
string to_string(pair<A, B> p)
{   return "("+to_string(p.F)+", "+to_string(p.S)+")"; }

template<typename A>
string to_string(A v)
{
    bool first=1; string res="{";
    for(const auto &x:v)
    {
        if(!first)  res+=", ";
        first=0;
        res+=to_string(x);
    }
    res+="}";
    return res;
}

void debug() { cout<<"\n"; }
template<typename Head, typename... Tail>
void debug(Head H, Tail... T)
{
    cout<<" "<<to_string(H);
    debug(T...);
}

#define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
/*-----</Debugging Stuff>-----*/

/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1;
/*-----</Constants>-----*/

vi v(3);
int k;

bool go(vi a,int d)
{
    if(d==k)
        return (a[0]<a[1] && a[1]<a[2]);

    bool res=0;
    for(int i=0;i<3;++i)
    {
        a[i]*=2;
        res|=go(a,d+1);
        a[i]/=2;
    }

    return res;
}

void solve()
{
    for(auto& c:v)
        cin>>c;

    cin>>k;

    if(go(v,0))
        cout<<"Yes";
    else
        cout<<"No";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 3612
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int gcd(int a, int b){
    return b ? gcd(b, a % b) : a;
}
int main(){
    int n, x;
    cin >> n >> x;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int g = abs(a[0] - x);
    for(int i = 0; i < n-1; i++){
        g = gcd(g, abs(a[i] - a[i+1]));
    }
    cout << g;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n;
    int a = n / 10;
    int b = n % 10;
    if (a == 9 || b == 9)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>

#define		MXCLEN		1000

int		main(void)
{
	int		i;
	int		x, sum;
	char	str[MXCLEN]={0};

	sum = 0;

	while(1)
	{
		for(i=0; i<MXCLEN; i++)
		{
			str[i]=0;
		}
		fgets( str, MXCLEN+5, stdin);
		if(strncmp(str,"0",1) == 0)
		{
			//printf("a\n");
			return 0;
		}
		//printf("str=%s\n",str);

		for(i=0; i<MXCLEN; i++)
		{
			if(( '0' <= str[i]) && (str[i] <= '9'))
			{
				x = str[i];
				x = x - '0';
				//printf("x=%d ",x);
				sum = sum + x;
			}
		}
		printf("%d\n",sum );
		sum = 0;
	}
	return 0;
}

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

using ll = long long;

#define mod 2019
#define INF 2<<30

int main(void){
    // Your code here!
    ll l,r;
    cin >> l >> r;
    
    if(r+1-l>=mod)
    {
        cout<<0;
        return 0;
    }
    
    int m=mod;
    
    for(int i=l;i<r;i++)for(int j=l+1;j<=r;j++)
    {
        m=min(((i%mod)*(j%mod))%mod,m);
    }
    
    cout<<m<<endl;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, M;
    cin>>N>>M;
    vi a(N), b(M);
    REP(i, 0, N) cin >> a[i];
    REP(i, 0, M) cin >> b[i];
    vi c;
    c = convolution<998244353>(a, b);
    REP(i, 0, N + M - 1) cout << c[i] << " ";
    cout << endl; 
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int R,G;
   cin>>R>>G;
   cout<<G*2-R;
   return 0; 
}


Measured memory_bytes: 256
open System
let curry f a b = f (a, b)

[<EntryPoint>]
let main argv =
    let weathers = [|"Sunny";"Cloudy";"Rainy";"Sunny"|]
    let s = Console.ReadLine()
    weathers.[(weathers |> Array.findIndex (fun x -> x = s)) + 1] |> Console.WriteLine
    0

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
struct snod
{
    vector <int> v;
    int len,leg;
} nod[100005];
int n,m,i,x,y,maxi;
queue <int> q;
int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        nod[x].v.push_back(y);
        nod[y].leg++;
    }
    for(i=1;i<=n;i++)
        if(!nod[i].leg)
        {
            q.push(i);
        }

    while(!q.empty())
    {
        int poz=q.front();
        for(int it : nod[poz].v)
        {
            nod[it].len=max(nod[it].len, nod[poz].len+1);
            nod[it].leg--;
            if(!nod[it].leg)
                q.push(it);
        }
        q.pop();
    }
    for(i=1;i<=n;i++)
    {
        maxi=max(maxi, nod[i].len);
    }
    cout<<maxi;
    return 0;
}


Measured memory_bytes: 6528
s = input()

alphabet = ''
for i in range(26):
    alphabet += chr(ord('a')+i)

res = float('inf')
for c in alphabet:
    tmp = 0
    t = s
    while t!=t[0]*len(t):
        u = ''
        for d,e in zip(t[::-1],t[::-1][1:]):
            if d==c or e==c:
                u += c
            else:
                u += d
        tmp += 1
        t = u[::-1]
    res = min(res,tmp)
print(res)


Measured memory_bytes: 3064
#include<stdio.h>

int a[8][8]={0};

void printtt(){
    int i,j;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(a[i][j]==1)printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}

 int check(int y,int x){
    int i,j;
    for(i=0;i<8;i++){
        if(i!=x && a[y][i]==1)return 0;
    }
    for(i=0;i<8;i++){
        if(i!=y && a[i][x]==1)return 0;
    }
    i=y-1; j=x+1;
    while(i>=0 && j<8){
        if(a[i--][j++]==1)return 0;
    }
    i=y-1; j=x-1;
    while(i>=0 && j>=0){
        if(a[i--][j--]==1)return 0;
    }
    i=y+1; j=x-1;
    while(i<8 && j>=0){
        if(a[i++][j--]==1)return 0;
    }
    i=y+1; j=x+1;
    while(i<8 && j<8){
        if(a[i++][j++]==1)return 0;
    }
    return 1;
}

 int pppp(int d){
    int i;
    for(i=0;i<8;i++){
        if(a[d][i]==1){
            if(!pppp(d+1))return 0;
        }
    }
    if(d==8){
        printtt();
        return 1;
    }

    else {
        for(i=0;i<8;i++){
            if(a[d][i]==0 && check(d,i)){
                a[d][i]=1;
                if(!pppp(d+1)){
                    a[d][i]=0;
                }
            }
        }
    }
    return 0;
}

 int main(){
    int n, i, j;
    int k, l;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d %d",&k,&l);
        a[k][l]=1;
    }

    l = pppp(0);

    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
    int c;
    string s,t;
    cin >> s >> t;
    if(s.size()<t.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    } 
    bool flag1 = 0;
    for(int i=0;i<=s.size()-t.size();i++){
        string u = s.substr(i,t.size());
        bool flag2 = 0;
        for(int j=0;j<t.size();j++){
            if(t.at(j)==u.at(j)||u.at(j)=='?') continue;
            else flag2 = 1;
        }
        if(!flag2){
           c = i;
           flag1 = 1;
        }  
    }
    if(!flag1) cout << "UNRESTORABLE" << endl;
    else{
        for(int i=0;i<s.size();i++){
            if(i<c||c+t.size()<=i){
                if(s.at(i)=='?') cout << 'a';
                else cout << s.at(i);
            }
            else{
                cout << t;
                i+=t.size()-1;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int x;
	scanf("%d",&x);
	int i,max = 1,t = 1;
	for(i = 2;i <= x;i++){
		if ( (i * i) <= x){
			t = i * i;
		}
		while ( t * i <= x){
			t = t * i;
		}
		if (max < t){
			max = t;
		}
	}
	printf("%d",max);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define imp() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define endl "\n"
#define lli long long int 
#define ll long long 
int main() {
	// your code goes here
	imp();
	
	  //  lli n;cin>>n;
	   lli n;cin>>n;
	   lli arr[n];
	   for(lli i=0;i<n;i++)
	   {
	       cin>>arr[i];
	       
	   }
	   sort(arr,arr+n);int c=0;
	   for(lli i=0;i<n;i++)
	   {
	       for(lli j=i+1;j<n;j++)
	       {
	           for(lli k=j+1;k<n;k++)
	           {
	               if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i] && arr[i]+arr[j]>arr[k])
	               {
	                   c++;
	                   //break;
	               }
	               
	           }
	       }
	   }
	   cout<<c<<"\n";
	   
	   

	
	   
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MIN -100000
using namespace std;

int solve(const vector<int>& v,int k) {
  int mx = MIN;
  int i = 0;
  auto begin = v.begin();
  while(i++ < v.size() - k) {
    mx = max(mx, accumulate(begin, begin + k, 0));
    begin++;
  }

  return mx;
}

int main() {
  int n, k;
  while (cin >> n >> k, n | k) {
    vector<int> v(n);
    for(auto i = 0; i < n; i++) cin >> v[i];

    cout << solve(v, k) << endl;
  }
  return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, D;
ll X[20][20];
std::map<ll, ll> isq;

int main() {
  std::cin >> N >> D;

  rep( i, N ) {
    rep( j, D )
      std::cin >> X[i][j];
  }

  rep( i, 1000 )
    isq[i*i] = i;

  ll ans = 0;

  rep( i, N ) rep( j, i ) {
    ll sum = 0;

    rep( k, D )
      sum += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);

    if( isq.count(sum) )
      ++ans;
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 3005;
const int MOD = 998244353;
ll N,S,A[MN],D[MN],ans;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> S;
    for(int i=1; i<=N; i++){
        cin >> A[i];
        D[0] = i;
        if(S>=A[i]) ans = (ans+D[S-A[i]]*(N-i+1))%MOD;
        for(int x=S; x>=0; x--){
            if(A[i]+x>S) continue;
            D[A[i]+x] = (D[A[i]+x]+D[x])%MOD;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio;
int[] readints() { return readln.split.to!(int[]); }

long calc(long n, long k, long b) {
    long cnt = max(0, b - k);
    long p = n / b;
    long r = n - p * b;
    long x = max(0, r - k + 1);
    return p * cnt + x;
}

void main() {
    auto input = readints();
    long n = input[0], k = input[1];

    long ans;
    foreach (b; k+1..n+1)
        ans += calc(n, k, b);
    writeln(!k ? n * n : ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int s;
    cin>>s;
    int cnt=1;
    map<int,int> mp;
    while(1){
        if(mp.count(s)){
            cout<<cnt<<endl;
            return 0;
        }
        mp[s]=cnt;
        cnt++;
        if(s%2==0)s/=2;
        else s=3*s+1;
    }
}

Measured memory_bytes: 3640
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n, x, t;
    cin >> n >> x >> t;

    print((n + x - 1) / x * t);
    
}


Measured memory_bytes: 3604
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int H, W;
        int i, j;
        int sw, line_sw; //sw: 0 -> #, 1 -> .

        while (scanf("%d %d", &H, &W), (H != 0) || (W != 0)) {
                line_sw = 0;
                for (i = 0; i < H; i++) {
                        sw = line_sw;
                        for(j = 0; j < W; j++) {
                                if (sw == 0) printf("#");
                                else printf(".");
                                sw = !sw;
                        }
                        printf("\n");
                        line_sw = !line_sw;
                }
                printf("\n");
        }
        return 0;
}

Measured memory_bytes: 572
#include <cstdio>
typedef long long ll;
int n, a, b, l, r=1e9, m, ans, h[100005];

bool f(int p) {
	ll i, c=0;
	for(i=0; i<n; i++)
		c += h[i] > (ll)p*b ? (h[i]-p*b+a-1)/a : 0;
	return c<=p;
}

int main() {
	scanf("%d%d%d", &n, &a, &b);
	a -= b;
	for(int i=0; i<n; i++) scanf("%d", &h[i]);
	while(l<=r) {
		m = (l+r) / 2;
		if(f(m)) r = m-1, ans = m;
		else l = m+1;
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner s = new Scanner(System.in);
		try{
			while(true){
				int n = s.nextInt();
				int m = s.nextInt();
				if(n + m == 0) return;

				int a[] = new int[n + m];
				for(int i = 0; i < n + m; i++){
					a[i] = s.nextInt();
				}

				Arrays.sort(a);
				//print(a);

				int max = a[0];
				for(int i = n+m-2; i >= 0; i--){
					if(max < a[i+1] - a[i]) max = a[i+1] - a[i];
				}

				System.out.println(max);
			}
		}catch(Exception e){
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 63652
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, W;
int w[210], acc[210];
int dp[201][10001];

signed main() {
    cin >> N >> W;
    rep(i,0,N) cin >> w[i];
    sort(w, w+N, greater<int>());

    rep(i,0,N) acc[i+1] = acc[i] + w[N-i-1];
    
    dp[0][0] = 1;
    rep(i,0,N) repq(j,0,W) {
        dp[i+1][j] = dp[i][j];
        if(j-w[i] >= 0) (dp[i+1][j] += dp[i][j-w[i]]) %= MOD;
    }
    repq(i,0,N) repq(j,1,W) (dp[i][j] += dp[i][j-1]) %= MOD;

    int ans = (W-acc[N] < 0 ? 0 : dp[N][W-acc[N]]);
    rep(i,0,N) {
        int sum = acc[i];
        if(W-sum < 0) continue;
        int vr = dp[N-i-1][W-sum];
        int vl = (W-sum-w[N-i-1] < 0 ? 0 : dp[N-i-1][W-sum-w[N-i-1]]);
        (ans += (vr - vl + MOD)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18788
#include <iostream>
#include <algorithm>

using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r,n!=0){
    int s[n];
    for(int i=0;i<n;i++){
      s[i] = n -i;
    } 
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      int tmp[c];
      for(int i=0;i<c;i++){
	tmp[i] = s[p+i-1];
      }
      for(int i=0;i<p-1;i++){
	s[c+p-2-i] = s[p-2-i];
      }
      for(int i=0;i<c;i++){
	s[i] = tmp[i];
      }
    }
    cout << s[0] << endl;
  }
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<math.h>
struct P{double x,y;}p[4],a,b;
P operator-(P l,P r){P a={l.x-r.x,l.y-r.y};return a;}
int main()
{
	int T;
	for(scanf("%d",&T);T--;)
	{
		int i;
		double c;
		for(i=0;i<4;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
		a=p[0]-p[1],b=p[2]-p[3];
		c=a.x*b.y-a.y*b.x;
		puts(fabs(c)<1e-10?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
n, m = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(m)]
one = set()
two = set()

for i in arr:
    if i[0] == 1:
        one.add(i[1])
    elif i[1] == n:
        two.add(i[0])

if len(one & two) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 58884