akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  rrep(i,2000050)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

ll nCr(int N,int K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

ll nHr(int N, int K){
  if(!N&&!K)return 1;
  if(!N)return 0;
  return nCr(N+K-1, K);
}

void Main() {
  init();
  ll n,m;
  cin >> n >> m;
  REP(i,1,m+1) {
    ll x=n-m;
    if(x==0) {
      if(i==1) pr(1);
      else pr(0);
      continue;
    }
    ll ans=nCr(m-1,i-1)*nCr(x-1,i-1)*2%MAX;
    ans+=nCr(m-1,i-1)*nCr(x-1,i)%MAX;
    ans+=nCr(m-1,i-1)*nCr(x-1,i-2)%MAX;
    pr(ans%MAX);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi find_divisor(int M){
  vi ans;
  for (int i=1;i*i<=M;++i){
    if(M%i==0){
      ans.push_back(i);
      ans.push_back(M/i);
    }
  }
  sort(ans.begin(), ans.end());
  return ans;
} 

int main(){
  int N,M;cin>>N>>M;
  vi divisors=find_divisor(M);
  int ub=upper_bound(divisors.begin(), divisors.end(), M/N)-divisors.begin();
  int ans=divisors[ub-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a,int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(void) {
	int seq[100];
	int n;
	int i,j;
	int swap_count = 0;

	scanf("%d",&n);
	for (i = 0;i != n;++i) {
		scanf("%d",seq + i);
	}
	// bubble sort
	for (i = 0;i != n;++i) {
		for (j = n - 1;j != i;--j) {
			if (seq[j - 1] > seq[j]) {
				swap(seq + j,seq + j - 1);
				++swap_count;
			}
		}
	}
	for (i = 0;i < n;++i) {
		printf("%d",seq[i]);
		printf(i == n - 1 ? "\n" : " ");
	}
	printf("%d\n",swap_count);
	return 0;
}

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

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

bool mysort(pair<ll,ll> a, pair<ll,ll> b){
    return a.second > b.second;
}

void virus(){
        ll n,m;
        cin>>n>>m;
        ll spt;
        cin>>spt;
        ll col[m] = {}, row[n] = {};
        set<pair<ll,ll>> ss;
        while(spt--){
            ll i,j;
            cin>>i>>j;
            i--,j--;
            col[j]++;
            row[i]++;
            ss.insert({i,j});
        }
        
        ll colmx = *max_element(col,col+m); ll rowmx = *max_element(row,row+n);
        ll colmxp = max_element(col,col+m) - col; ll rowmxp = max_element(row,row+n) - row;
        ll sum = colmx+rowmx;
        vector<ll> indxx, indy;
        for(auto i=0; i<n; i++){
            if(row[i] == rowmx) indxx.push_back(i);
        }
        for(auto i=0; i<m; i++){
            if(col[i] == colmx) indy.push_back(i);
        }
        sum -= 1;
        for(auto i:indxx){
            for(auto j:indy){
                if(ss.count({i,j}) == 0){
                    sum += 1; goto here;
                }
            }
        }
        here:;
        cout<<sum;

}


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

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

Measured memory_bytes: 34960
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];
		for(int i=0;i<N;i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		int count=0;
		long pre = a[a.length-1];
		List<Long> l = new ArrayList<>();
		for(int i=a.length-1;i>=0;i--) {
			if(a[i] == pre) {
				count++;
			}else {
				count = 1;
			}
			pre = a[i];

			if(count % 2 == 0) l.add(a[i]);
			if(l.size() >= 2) break;
		}

		if(l.size() < 2) {
			System.out.println(0);
		}else {
			System.out.println(l.get(0) * l.get(1));
		}
	}
}


Measured memory_bytes: 49460
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN")
		cout<<7;
	if(s=="MON")
		cout<<6;
	if(s=="TUE")
		cout<<5;
	if(s=="WED")
		cout<<4;
	if(s=="THU")
		cout<<3;
	if(s=="FRI")
		cout<<2;
	if(s=="SAT")
		cout<<1;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int u[33][33];
int dp[33][33][33][33][2];
int sum[33][33];
int h, w, s;
int INF = 100000000;

void f(int sy, int sx, int gy, int gx) {
  if (dp[sy][sx][gy][gx][0] != INF) return;
  int sm = sum[gy][gx] - sum[gy][sx] - sum[sy][gx] + sum[sy][sx];
  if (sum[h][w] - sm > s) {
    dp[sy][sx][gy][gx][0] = -INF;
    return;
  }
  int res0 = 1, res1 = sm;
  for (int i = sy + 1; i < gy; ++i) {
    f(sy, sx, i, gx);
    f(i, sx, gy, gx);
    int a = dp[sy][sx][i][gx][0];
    int b = dp[sy][sx][i][gx][1];
    int c = dp[i][sx][gy][gx][0];
    int d = dp[i][sx][gy][gx][1];
    if (res0 < a + c || (res0 == a + c && res1 < min(b, d))){
      res0 = a + c;
      res1 = min(b, d);
    }
  }
  for (int i = sx + 1; i < gx; ++i) {
    f(sy, sx, gy, i);
    f(sy, i, gy, gx);
    int a = dp[sy][sx][gy][i][0];
    int b = dp[sy][sx][gy][i][1];
    int c = dp[sy][i][gy][gx][0];
    int d = dp[sy][i][gy][gx][1];
    if (res0 < a + c || (res0 == a + c && res1 < min(b, d))){
      res0 = a + c;
      res1 = min(b, d);
    }
  }
  //cout << sy << " " << sx << " " << gy <<" " << gx << " " << res0 << " " << res1 << endl;
  dp[sy][sx][gy][gx][0] = res0;
  dp[sy][sx][gy][gx][1] = res1;
}

int main() {
  for (;;) {
    cin >> h >> w >> s;
    if (h == 0 && w == 0 && s == 0) break;
    rep (i, h) rep (j, w) cin >> u[i][j];
    rep (i, h + 1) rep (j, w + 1) rep (ii, h + 1) rep (jj, w + 1) dp[i][j][ii][jj][0] = INF;
    rep (i, h + 1) rep (j, w + 1) sum[i][j] = 0;
    rep (i, h) rep (j, w) {
      sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + u[i][j];
      //cout << i << " " << j << " " << sum[i + 1][j + 1] << endl;
    }
    f(0, 0, h, w);
    cout << dp[0][0][h][w][0] << " " << s - (sum[h][w] - dp[0][0][h][w][1]) << endl;
  }
}

Measured memory_bytes: 9748
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0

for i in range(min(x//500 + 1,a + 1)):
    for j in range(min((x-i*500)//100 + 1,b + 1)):
        if (x-i*500-j*100)%50==0 and (x-i*500-j*100)//50 <= c:
            count += 1

print(count)


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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define TL printf("Time elapsed: %gs.\n",1.0 * clock() / CLOCKS_PER_SEC)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);

inline string IntToString(LL a){
  	char x[100];
  	sprintf(x,"%lld",a); string s = x;
  	return s;
}

inline LL StringToInt(string a){
  	char x[100]; LL res;
  	strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  	return res;
}

inline string GetString(void){
  	char x[1000005];
  	scanf("%s",x); string s = x;
  	return s;
}

inline string uppercase(string s){
  	int n = SIZE(s); 
  	REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  	return s;
}

inline string lowercase(string s){
  	int n = SIZE(s); 
  	REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  	return s;
}

inline void OPEN (string s) {
  	#ifndef TESTING
  	freopen ((s + ".in").c_str (), "r", stdin);
  	freopen ((s + ".out").c_str (), "w", stdout);
  	#endif
}
void check(string s) {
    int l = 0,ans=0; 
    int h = SIZE(s)-1;   
    while (h > l) 
    { 
        if (s[l++] != s[h--]) ans++; 
    } 
    printf("%d\n", ans);
}
int main() {
	// FASTIO;
 	// Start Program
    string s;
    s = GetString(); 
    check(s);
	// End of Program Jangan Lupa diComment TL
	//TL; 	
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N, long long K, std::vector<long long> D){
    FOR(j, N, 100*N) {
        bool flag = true;
        rep(i, floor(log10(j))+1) {
            int keta = int(j / pow(10, i)) % 10;
            if (find(D.begin(), D.end(), keta) != D.end()) {
                flag = false;
            }
        }
        if (flag) {
            cout << j << endl;
            break;
        }
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> D(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&D[i]);
    }
    solve(N, K, std::move(D));
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=2010,MOD=int(1e9)+7;
int N,M,a[maxn],b[maxn],f[maxn][maxn];
int main(){
	//freopen("in","r",stdin);
	N=read(),M=read();
	for(int i=1;i<=N;i++)
		a[i]=read();
	for(int i=1;i<=M;i++)
		b[i]=read();
	for(int i=0;i<maxn;i++)
		f[i][0]=f[0][i]=1;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
			if(i+j){
				f[i][j]=((f[i][j-1]+f[i-1][j]-f[i-1][j-1])%MOD+MOD)%MOD;
				if(a[i]==b[j])
					(f[i][j]+=f[i-1][j-1])%=MOD;
			}
	printf("%d\n",f[N][M]);
	return 0;
}



Measured memory_bytes: 16000
#include <stdio.h>



int BubbleSort(int *p,int len){

  int i,j,tmp,c=0;
  for(i=0;i<len;i++){
    for(j=len-1;j>i;j--){
      if(p[j] < p[j-1]){
        tmp = p[j];
        p[j]=p[j-1];
        p[j-1]=tmp;
        c++;
      }
    }
  }
    return c;

}

main(){

    int i,a,c=0;
    int A[100];
    scanf("%d",&a);

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


    c=BubbleSort(A,a);

    printf("%d",A[0]);

    for(i=1;i<a;i++){
      printf(" %d" ,A[i]);
    }

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

   return 0;
  }

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[int(s.size() - 1)] == 's') cout << s << "es" << endl;
  else cout << s << 's' << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
        string str;
        cin >> str;
        for( int i=0 ; i<str.size() ; i++ )
                if(int(str[i])<=67)
                        printf("%c",str[i]+26-3);
                else
                        printf("%c",str[i]-3);
        cout << endl;
        return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;

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

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

    vector<int>::iterator maxItr = max_element(a.begin(), a.end());
    vector<int>::iterator minItr = min_element(a.begin(), a.end());
    size_t maxIndex = distance(a.begin(), maxItr);
    size_t minIndex = distance(a.begin(), minItr);
    cout<<2*n-2<<endl;
    if(abs(*maxItr)>abs(*minItr)) {
        for(int i=0; i<n; i++) {
            if(i==maxIndex) continue;
            cout<<maxIndex+1<<" "<<i+1<<endl;
        }
        for(int i=0; i<n-1; i++) {
            cout<<i+1<<" "<<i+2<<endl;
        }
    } else{
        for(int i=0; i<n; i++) {
            if(i==minIndex) continue;
            cout<<minIndex+1<<" "<<i+1<<endl;
        }
        for(int i=n-1; i>0; i--) {
            cout<<i+1<<" "<<i<<endl;
        }
    }
}

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

int count(int c, int d);

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

    int a[n];

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

    int c[n];

    for(int i = 0; i < n; i++) {
        c[i] = count(a[i], d);
    }

    int ans = x;

    for(int i = 0; i < n; i++) {
        ans += c[i];
    }

    cout << ans << endl;
}

int count(int c, int d) {
    int count =0;
    for(int j = 0; d >= (j*c) + 1; j++) {
        count++;
    }
    return count;
}

Measured memory_bytes: 256
#include <iostream>

int main ()
{
    int N, x, y, z, X, Y, Z;
    std::cin >> N;
    for (int n = N; n > 0; --n) {
        std::cin >> x >> y >> z;
        X = x * x;
        Y = y * y;
        Z = z * z;
        if (X + Y == Z || Y + Z == X || Z + X == Y) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d",a*b);
}


Measured memory_bytes: 1736
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	foreach(nd; nodes) foreach(_; 0 .. rint) nd.connectTo(nodes[rint]);

	Node.root = nodes[0];

	foreach(_; 0 .. rint){
		Node p = nodes[rint], q = nodes[rint];
		p.lca(q).id.writeln;
	}
}

// 最小共通祖先, lca, 最低共通祖先, Lowest Common Ancestor, Least Common Ancestor
// パスの長さ, 木上の距離, ツリー上の距離, ツリーでの最短経路の長さ
// ※ループがある場合や、森になっている場合は非対応
class Node{
	static Node[] all; // 存在する全てのノード
	int id;
	Node[] nodes; // 隣接ノード（親も子も含む）
	int depth; // 根は 0
	Node[] parents; // 1代前、2代前、4代前、8代前、…… の親（いない場合は打切り）
	private bool isDone;

	// 頂点を作成（根付き木は壊れる）
	this(int id){
		this.id = id;
		all ~= this;
		_root = null;
	}

	// 辺を作成（根付き木は壊れる）
	void connectTo(Node nd){
		this.nodes ~= nd, nd.nodes ~= this;
		_root = null;
	}

	// 根付き木にする（木になってない場合は未定義）
	private static Node _root;
	static Node root(){ return _root; }
	static Node root(Node r){

		// parents[0] を設定する
		foreach(nd; all) nd.isDone = 0;
		r.parents = [], r.depth = 0;
		Node[] ndq = [r];
		for(int i = 0; i < ndq.length; i ++){
			Node p = ndq[i];
			p.isDone = 1;
			foreach(q; p.nodes) if(! q.isDone){
				q.parents = [p], q.depth = p.depth + 1;
				ndq ~= q;
			}
		}

		// parents[1] 以降を設定する（30 はマジックナンバー、log(2;N) 程度）
		foreach(i; 1 .. 30) foreach(nd; all){
			if(i <= nd.parents.length){
				Node par = nd.parents[i - 1];
				if(i <= par.parents.length) nd.parents ~= par.parents[i - 1];
			}
		}

		return _root = r;
	}
	
	// 2点間の距離
	int distTo(Node nd){
		Node p = this.lca(nd);
		return (this.depth - p.depth) + (nd.depth - p.depth);
	}

	// 最小共通祖先
	Node lca(Node nd){
		assert(root);
		if(this.depth > nd.depth) return nd.lca(this);
		if(this.depth < nd.depth) foreach_reverse(p; nd.parents) if(p.depth >= this.depth) return lca(p);
		foreach_reverse(i, p; nd.parents) if(this.parents[i].id != p.id){
			return this.parents[i].lca(p);
		}
		if(this.id == nd.id) return this; else return this.parents[0];
	}
}


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

int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll>> vec(m);
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        vec[i]=make_pair(b,a);
    }
    sort(vec.begin(),vec.end());
    ll memo=-1;
    ll res=0;
    for(ll i=0;i<m;i++){
        if(memo>=vec[i].second) continue;
        else if(memo<vec[i].second){
            memo=vec[i].first-1;
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 4848
/**
 *    author:  tourist
 *    created: 11.01.2020 14:33:51       
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> deg(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
    deg[a[i]] += 1;
  }
  vector<int> b(n, -1);
  vector<int> used(n, 0);
  function<void(int, int)> Dfs = [&](int v, int mn) {
    if (v == n) {
      for (int i = 0; i < n; i++) {
        if (i > 0) {
          cout << " ";
        }
        cout << b[i] + 1;
      }
      cout << '\n';
      exit(0);
    }
    if (v > 0) {
      int who = a[b[v - 1]];
      if (!used[who] && deg[who] == n - v - 1) {
        return;
      }
    }
    while (used[mn]) {
      ++mn;
    }
    for (int i = mn; i < n; i++) {
      if (used[i]) {
        continue;
      }
      if (v > 0 && i == a[b[v - 1]]) {
        continue;
      }
      int new_mn = mn;
      if (i == mn) {
        ++new_mn;
      }
      b[v] = i;
      --deg[a[i]];
      used[i] = 1;
      Dfs(v + 1, new_mn);
      used[i] = 0;
      ++deg[a[i]];
      b[v] = -1;
    }
  };
  Dfs(0, 0);
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 13312
#include <iostream>
#include <map>

using namespace std;

void solve(int n) {
  string names[50];
  int times[50][50] = {{0}};
  int points[50] = {0};

  for (int i = 0; i < n; i++) {
    cin >> names[i];
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int d;
      cin >> d;
      times[i][d] = 1;
    }
  }

  for (int j = 0; j < 50; j++) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (times[i][j] == 1)
        count++;
    }
    for (int i = 0; i < n; i++) {
      if (times[i][j] == 1)
        points[i] += (n - count + 1);
    }
  }

  int min = points[0];
  int min_i = 0;
  for (int i = 1; i < n; i++) {
    if (points[i] < min || (points[i] == min && names[i].compare(names[min_i]) < 0)) {
      min_i = i;
      min = points[i];
    }
  }
  cout << points[min_i] << " " << names[min_i] << endl;
}

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    solve(n);
  }
  return 0;
}

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

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

    int a = -1, b = -1, c = -1;
    bool flg = false;
    // i: 10000の枚数
    for (int i = 0; i <= n; i++) {
        // i: 5000の枚数
        for (int j = 0; j <= n; j++) {
            if (i + j > n) continue;

            // k: 1000の枚数
            int k = n - i - j;
            if (k < 0) continue;

            int m = 10000 * i + 5000 * j + 1000 * k;
            if (m == y) {
                a = i; b = j; c = k;
                flg = true;
                break;
            }
        }
        if (flg) break;
    }

    cout << a << " " << b << " " << c << endl;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

int main()
{
	int n;cin >> n;
	vector<pair<int,int>> v;
	vector<int> ans(n);
	REP(i,n){
		int tmp;
		cin >> tmp;
		v.PB(MP(tmp,i));
	}
	
	sort(ALL(v));
	
	
	REP(i,n){
		if(i < (n/2)){
			ans[v[i].SE] = v[n/2].FI;
		}else
		{
			ans[v[i].SE] = v[n/2 - 1].FI;
		}
	}
	
	REP(i,n){
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4720
using System;
using System.Linq;

namespace Library
{
}

namespace AtCoder
{
    using Library;
    class ABC079_C
    {
        static bool Solve(int n, string Str, long sum, long[] input)
        {
            if (n == 3)
            {
                if (sum == 7)
                {
                    Console.WriteLine(Str + "=7");
                    return true;
                }
                else return false;
            }
            else
            {
                return Solve(n + 1, Str + "+" + input[n + 1].ToString(), sum + input[n + 1], input) || Solve(n + 1, Str + "-" + input[n + 1].ToString(), sum - input[n + 1], input);
            }
        }
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Select(i => long.Parse(i.ToString())).ToArray();
            Solve(0, input[0].ToString(), input[0], input);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> path[n];
	vector<ll> h(n);
	rep(i, n) {
		cin >> h[i];
	}
	rep(i, n) {
		path[i] = vector<ll>(0);
	}
	rep(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	ll ans = 0;
	rep(i, n) {
		bool tmp=true;
		for (ll j : path[i]) {
			if (h[i] <= h[j])tmp = false;
		}
		if (tmp)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 9368
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int ans = 0;
    rep(i, 0, 4){
        char s;
        cin >> s;
        if(s == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <ll, int> P;

template <typename T>
class SegmentTree {
    using F = function<T(T, T)>;
    int n;
    F f;
    T t;
    vector <T> dat;
public:
    SegmentTree(F f, T t) : f(f), t(t) {}
    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        dat.assign(n << 1, t);
    }
    void build(const vector <T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
    void set_val(int k, T x) {
        dat[k += n] = x;
        while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
    T query(int a, int b) {
        T vl = t, vr = t;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, dat[l++]);
            if (r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

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

    int n;
    cin >> n;

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

    sort(a.begin(), a.end(), greater<P>());

    vector <vector <ll>> dp(n + 1, vector<ll>(n + 1));
    // i番目まで見て、左からjこ埋めてある時の最大値

    for (int i = 0; i < n; i++) {
        ll val = a[i].first;
        int idx = a[i].second;

        for (int j = 0; j <= i; j++) {
            int right = n - 1 - (i - j);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + val * abs(j - idx));
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + val * abs(idx - right));
        }
    }

    ll ans = 0;
    for (int j = 0; j <= n; j++) {
        ans = max(ans, dp[n][j]);
    }

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

Measured memory_bytes: 34616
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int res = 0;
    REP(i,4){
        if(s[i]=='+')res++;
        else res--;
    }
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool num[110];

int main() {
    int X, N; cin >> X >> N;
    for (int i = 0; i < 110; i++) num[i] = true;
    num[X] = true;
    for (int i = 0; i < N; i++) {
        int p; cin >> p;
        num[p] = false;
    }
    if (num[X]) {
        cout << X << endl;
        return 0;
    }
    int l = X-1, r = X+1;
    while (1) {
        if (num[l]) {
            cout << l << endl;
            return 0;
        } else {
            l -= 1;
        }
        if (num[r]) {
            cout << r << endl;
            return 0;
        } else {
            r += 1;
        }
    } 
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
using namespace std;
const long long mod = 1000000007LL, neg_INF = -0x7f7f7f7f7f7f7f7fLL;
int n, m;
long long way[101000];
int main(){
	scanf("%d%d", &n, &m);
	for( int i = 1, x; i <= m; ++i ){
		scanf("%d", &x);
		way[x] = neg_INF;
	}
	if( way[1] != neg_INF )
		way[1] = 1LL;
	if( way[2] != neg_INF ){
		way[2] = 1LL;
		if( way[1] != neg_INF )
			way[2] = 2LL;
	}
	for( int i = 3; i <= n; ++i ){
		if( way[i] == neg_INF )
			continue;
		if( way[i-1] != neg_INF )
			way[i] += way[i-1], way[i] %= mod;
		if( way[i-2] != neg_INF )
			way[i] += way[i-2], way[i] %= mod;
	}
	printf("%lld\n", way[n] == neg_INF ? 0 : way[n]);
	return 0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = a[0]
idx = 0
gabbege = a[idx]
length = 1
for i in range(1, n):
    if length < k:
        length += 1
        now += a[i]
    else:
        if now < now - gabbege + a[i]:
            print("Yes")
        else:
            print("No")
        now = now - gabbege + a[i]
        idx += 1
        gabbege = a[idx]

Measured memory_bytes: 31664
#include<cstdio>
int main(){
int n, d, x;
int a[101];
scanf("%d%d%d", &n, &d, &x);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
int ans=x;d--;
for(int i = 0; i < n; i++){
ans+=(d/a[i])+1;
}
printf("%d\n", ans);
}

Measured memory_bytes: 128
import math

A, B, H, M = map(int, input().split())

X = min(abs(6*M-0.5*(60*H+M)), 360-abs(6*M-0.5*(60*H+M)))
print((A**2+B**2-2*A*B*(math.cos(math.radians(X))))**0.5)

Measured memory_bytes: 9508
# babacccabab a4 b4 c3
# a bc a bc a bc a b
# bがひとつ少なくても、cがひとつ多くてもよさそう
# bがひとつ多い場合(a4 b5 c3)は無理そう
# なので登場するやつのminとmaxの差でいけそう
# と思ったらサンプル2の場合があるので、2種類しかない場合は基本的に無理そう
# ただし1文字だけしか無い場合はいけそう

# -> なんか1つだけWAなる
# -> よくよく考えたら ab みたいな場合はおｋだわ たぶんこれにひっかっかた
s = input()
if len(s) == 1:
    print("YES")
    exit()
abc = [s.count("a"), s.count("b"), s.count("c")]
if len(s) == 2 and max(abc) == 1:
    print("YES")
    exit()
if 0 in abc:
    print("NO")
else:
    print("YES" if max(abc) - min(abc) < 2 else "NO")

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


unsigned long int lcm(unsigned long int c, unsigned long int d){
  unsigned long int x = c * d;
  unsigned long int tmp, r ;

  if(c < d){
    tmp = c;
    c = d;
    d = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = c % d;
  while(r!=0){
    //cout << c << " " << d << " " << r << endl;
    c = d;
    d = r;
    r = c % d;
  }
  //cout << x << " " << d << endl;
  //cout << x / d << endl;
  return x / d;
}

int main() {
  unsigned long int A, B, E;
  unsigned long int C, D;
  cin >> A >> B >> C >> D;
  
  unsigned long int nc, nd, ne;
  
  // divide by C
  if ( (B - A + 1) % C > B % C) nc = (B - A + 1) / C + 1;
  else nc = (B - A + 1) / C;  
  // divide by D
  if ( (B - A + 1) % D > B % D) nd = (B - A + 1) / D + 1;
  else nd = (B - A + 1) / D;
  // divide by E
  E = lcm(C, D);
  if ( (B - A + 1) % E > B % E) ne = (B - A + 1) / E + 1;
  else ne = (B - A + 1) / E;
  //cout << nc << " " << nd << " " << ne << endl;
  cout << B - A + 1 - nc - nd + ne << endl;
}



Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

A=[0 for i in range(N)] 
A[0]=B[0]
A[N-1]=B[N-2]
if N > 2:
  for i in range(1,N-1):
    A[i] = min(B[i-1],B[i])
  
print(sum(A))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int position = 0;
		int count =1;
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			position +=temp;
			if(position >X) {
				break;
			}
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

// n以上におけるmの倍数から最小値を返す
long long int getMinP(long long int n,long long int m){
    if(n%m==0) return n;
    else return ((n/m)+1)*m;
}

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

    long long int a=1,b=1;
    for(int i=0;i<n;i++){
        long long int t_a,t_b;cin >> t_a >> t_b;

        a = getMinP(a,t_a);
        b = getMinP(b,t_b);

        if(a/t_a!=b/t_b){
            long long int p = max(a/t_a,b/t_b);
            a = t_a*p;
            b = t_b*p;
        }
    }
    p(a+b)
}

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

using namespace std;

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

set<int> pos[26];
string s, t;
ll num = 0, next_mult = s.size(), S;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s >> t;
	for (int i = 0; i < s.size(); ++i){
		pos[s[i]-'a'].insert(i);
	}
	S = s.size();
	for (int i = 0; i < t.size(); ++i){
		int x = t[i] - 'a';
		if (pos[x].size() == 0){
			cout << -1 << '\n';
			return 0;
		}
		auto it = pos[x].lower_bound(num%S);
		if (it == pos[x].end()){
			num = next_mult;
			auto it2 = pos[x].lower_bound(0);
			num = *it2+(num/S)*S;
			num++;
		}
		else{
			num = *it+(num/S)*S;
			num++;
		}
		next_mult = ((num+S-1)/S)*S;
	}
	cout << num << '\n';
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#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...);
}

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((c + b - 1) / b <= (a + d - 1) / d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500001;
typedef long long ll;
int main()
{
    int n, a[100];
    cin >> n;
    vector<int> idx;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(a[i]!=i)
        {
            idx.push_back(i);
        }
    }
    if(idx.size()>2)
    printf("NO\n");
    else if(idx.empty())
    printf("YES\n");
    else {
        if(idx[0]==a[idx[1]])
        printf("YES\n");
        else puts("NO");
    }

    return 0;
}

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

int gcd (int x, int y){
    if(x==0 || y==0){
        return max(x,y);
    }
    else if (x <= y){
        return gcd (y%x, x);
    }
    else return gcd (x%y,y);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++){
        cin >> A.at(i);
    }

    //  3 8 6 4
    //l 3 1 1 1
    //r 1 2 2 4  
    // 左からi番目までのgcdをlに管理  l.at(i-1)に
    // i番目以降のgcd

    vector<int> l(N);
    vector<int> r(N);

    l.at(0) = A.at(0);
    r.at(N-1)=A.at(N-1);

    for(int i=0; i<N-1; i++){
        l.at(i+1) = gcd(l.at(i), A.at(i+1));
    }
    for(int i=0; i<N-1; i++){
        r.at(N-i-2) = gcd(r.at(N-i-1), A.at(N-i-2));
    }

    int ans=1;
    
    ans = max (l.at(N-2), r.at(1));

    for(int i=0; i< N-2; i++){ // i+1番目を除いた場合
        ans = max (ans, gcd(l.at(i) , r.at(i+2)));
    }

    cout << ans << endl;

}

Measured memory_bytes: 1408
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = NK[0];
            var K = NK[1];

            //0が0個の時
            var ans = new Modular(1);

            //0がi個の時
            for (int i = 1; i <= K && i < N; i++)
            {
                var b = Modular.Ncr(N, i);
                ans +=  b* Modular.Ncr((N-1),N-i-1);
            }
            Console.WriteLine((int)ans); 
        }

    }

    class Modular
    {
        private const int M = 1000000007;
        public long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return (a.value + b.value) % M;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    var p = Pow(a, n / 2);
                    return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        private static Modular Fac(int n)
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Ncr(int n, int r)
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : Fac(n) / (Fac(r) * Fac(n - r));
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }

        public static Modular Lcm(Modular a, Modular b)
        {
            var tmp = Gcdl(a.value, b.value);
            return ((a * b) / new Modular(tmp));
        }
        static Modular Gcd(Modular m, Modular n)
        {
            if (n.value > m.value) return Gcd(n, m);
            if (n.value == 0) return m;
            var r = new Modular(m.value % n.value);
            return Gcd(n, r);
        }

        static long Gcdl(long m, long n)
        {
            if (n > m) return Gcdl(n, m);
            if (n == 0) return m;
            return Gcdl(n, m % n);
        }
    }
}


Measured memory_bytes: 18988
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

vector<int> to_vector(int n, int pattern) {
    vector<int> res(n);
    for(int i = 0; i < n; i++) {
        res.at(i) = (pattern & 1 << i) != 0;
    }
    return res;
}

int count_bit(int n, int pattern) {
    int res = 0;
    for(int i = 0; i < n; i++) {
        res += (pattern & 1 << i) != 0;
    }
    return res;
}

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

    vector<int> A(N);
    vector<vector<P>> xy;
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
        vector<P> axy(A.at(i));
        for(int j = 0; j < A.at(i); j++) {
            cin >> axy.at(j).first >> axy.at(j).second;
        }
        xy.push_back(axy);
    }

    int pattern = 0;
    for(int i = 0; i < N; i++) {
        pattern |= 1 << i;
    }

    int ans = 0;
    while(pattern >= 0) {
        vector<int> pv = to_vector(N, pattern);
        bool all_ok = true;
        for(int i = 0; i < N; i++) {
            vector<P> axy = xy.at(i);
            if(!pv.at(i)) {
                continue;
            }
            for(P a : axy) {
                if(a.second != pv.at(a.first - 1)) {
                    all_ok = false;
                    break;
                }
            }
        }
        if(all_ok) {
            ans = max(ans, count_bit(N, pattern));
        }
        pattern--;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define pb push_back
#define md 1000000007
vi adj[1000010];
void addEdge(int a , int b)
{
	adj[a].pb(b);
	adj[b].pb(a);
}
int main()
{
	fast;
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 2; i <= n; i++)
		cin >> a[i];
	for (int i = 2; i <= n; i++)
	{
		addEdge(a[i], i);
	}

	for (int i = 1; i <= n; i++)
	{
		if (i > 1)
			cout << adj[i].size() - 1 << endl;
		else
			cout << adj[i].size() << endl;

	}
	return 0;
}

Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n, d;
  double x, y;
  cin >> n;
  cin >> d;
  int counter = 0;

  


  rep(i, n) {
    cin >> x;
    cin >> y;
    
    double distance;
    double sqrt_distance;

    double absx = abs(x);
    double absy = abs(y);
    // cout << absx << " " << absy << endl;

    



    distance = ((absx * absx) + (absy * absy));
    // cout << distance << endl;

    sqrt_distance = sqrt(distance);

    // cout << sqrt_distance << endl;



    if (sqrt_distance <= d) {
      ++counter;
    }
  }

  cout << counter << endl;
}

Measured memory_bytes: 3820
import java.util.*;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    //整数の入力
    int W = sc.nextInt();
    int H = sc.nextInt();
    int N = sc.nextInt();
    int x, y, a;

    int max_x = 0;
    int min_x = W;
    int max_y = 0;
    int min_y = H;

    //繰り返し処理
    for(int i=0; i< N; i++){
      x = sc.nextInt();
      y = sc.nextInt();
      a = sc.nextInt();

      switch(a){
        case 1:
        if(max_x < x)max_x = x;
        break;

        case 2:
        if(min_x > x)min_x = x;
        break;

        case 3:
        if(max_y < y)max_y = y;
        break;

        case 4:
        if(min_y > y)min_y = y;
        break;
      }
    }

    //面積を求める
    if( (max_x >= min_x) || (max_y >= min_y) ){
      System.out.println(0);
    }else{
      int ans = (min_x - max_x)*(min_y - max_y);
      System.out.println(ans);

    }



  }
}


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

using namespace std;

int main(){
  
  	string s;
  
  	cin >> s;
  
  	int sz = s.size();
  
  	if(s[ sz - 1 ] == 's') s += "es";
 	else s += 's';
  	
  	cout << s << endl;
  	
 	return 0; 
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
vvi G;
pii dp[50][50][50][50];
int n,m,q,sum;
pii f(int a,int b,int c,int d){
    if(dp[a][b][c][d].first!=inf)return dp[a][b][c][d];
    dp[a][b][c][d]=pii(0,0);
    dp[a][b][c][d].second=G[c][d]-G[a][d]-G[c][b]+G[a][b];
//  cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<dp[a][b][c][d].second<<endl;
//  loop(i,a,c)loop(j,b,d)dp[a][b][c][d].second+=G[i][j];
    rep(i,c-a-1){
        pii ta=f(a,b,a+i+1,d);
        pii tb=f(a+i+1,b,c,d);
        if(min(ta.second,tb.second)==-inf)continue;
        if(dp[a][b][c][d].first<1+ta.first+tb.first){
            dp[a][b][c][d].first=1+ta.first+tb.first;
            dp[a][b][c][d].second=min(ta.second,tb.second);
        }else if(dp[a][b][c][d].first==1+ta.first+tb.first){
            dp[a][b][c][d].second=max(dp[a][b][c][d].second,min(ta.second,tb.second));
        }
    }
    rep(i,d-b-1){
        pii ta=f(a,b,c,b+i+1);
        pii tb=f(a,b+i+1,c,d);
        if(min(ta.second,tb.second)==-inf)continue;
        if(dp[a][b][c][d].first<1+ta.first+tb.first){
            dp[a][b][c][d].first=1+ta.first+tb.first;
            dp[a][b][c][d].second=min(ta.second,tb.second);
        }else if(dp[a][b][c][d].first==1+ta.first+tb.first){
            dp[a][b][c][d].second=max(dp[a][b][c][d].second,min(ta.second,tb.second));
        }
    }
    if(dp[a][b][c][d].second<sum)dp[a][b][c][d]=pii(-inf,-inf);
//  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
//  cout<<dp[a][b][c][d].first<<" "<<dp[a][b][c][d].second<<endl;
    return dp[a][b][c][d];
}
int main(){
    while(cin>>n>>m>>q,n+m+q){
        sum=-q;
        G=vvi(n+1,vi(m+1));
        rep(i,n)rep(j,m)cin>>G[i+1][j+1];
        rep(i,n)rep(j,m)G[i+1][j+1]+=G[i][j+1]+G[i+1][j]-G[i][j];
        sum=G[n][m]-q;
        rep(i,50)rep(j,50)rep(k,50)rep(l,50)
            dp[i][j][k][l]=pii(inf,inf);
        f(0,0,n,m);
        cout<<1+dp[0][0][n][m].first<<" "<<dp[0][0][n][m].second-sum<<endl;
    }
}

Measured memory_bytes: 51948