akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;

int main(){
    priority_queue<int>q1,q2;
    int a,b;
    for(int i=0;i<4;i++){
        cin>>a;
        q1.push(a);
    }
    for(int i=0;i<2;i++){
        cin>>a;
        q2.push(a);
    }
    for(int i=0;i<3;i++){
        b+=q1.top();
        q1.pop();
    }
    cout<<b+q2.top()<<endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
long long aa;bool bb;char ch;
long long scan()
{
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	ch=='-'?(bb=1,aa=0):(bb=0,aa=ch-48);
	while(ch=getchar(),(ch>='0'&&ch<='9'))
		aa=aa*10+ch-48;
	return (bb?(-aa):(aa));
}
long long r,c,n,tot=0;
struct P
{
	long long x,y,id;
	double ang;
} p[200010];
long long x,y,xx,yy;
bool cmp(P u,P v){return u.ang<v.ang;}
bool vis[200010];
stack<long long> st;
int main()
{
	scanf("%lld%lld%lld",&r,&c,&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld%lld%lld%lld",&x,&y,&xx,&yy);
		if(x!=0&&x!=r&&y!=0&&y!=c)
			continue;
		if(xx!=0&&xx!=r&&yy!=0&&yy!=c)
			continue;
		p[++tot].x=x;p[tot].y=y;p[tot].id=i;
		p[tot].ang=atan2(p[tot].y-c/2.0,p[tot].x-r/2.0);
		p[++tot].x=xx;p[tot].y=yy;p[tot].id=i;
		p[tot].ang=atan2(p[tot].y-c/2.0,p[tot].x-r/2.0);
	}
	sort(p+1,p+tot+1,cmp);
	for(int i=1;i<=tot;++i)
	{
		if(!vis[p[i].id])
		{
			vis[p[i].id]=1;
			st.push(p[i].id);
		}
		else if(st.top()==p[i].id)
			st.pop();
		else
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 6912
n, k = map(int, input().split())
M = 10**9 + 7

def f(a,b):
    return (a+b)*(b-a+1)//2

ans = 0
for s in range(k, n+2):
    l = f(0,s-1) % M
    r = f(n-s+1,n) % M
    ans += r-l+1

print(ans%M)


Measured memory_bytes: 9004
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b&&b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

double sisya(double x)
{
	int a = static_cast<int>(x * 10000);
	x = static_cast<double>(static_cast<int>(x * 1000)) / 1000;
	if(a < 0 && a%10 <= -5)
		return x-0.001;
	else if(a%10 >= 5)
		return x+0.001;
	return x;
}

int main()
{
	int n;
	double x1,x2,x3,y1,y2,y3;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double px = ((y1-y2)*(x3*x3+y3*y3-x1*x1-y1*y1)-(y1-y3)*(x2*x2+y2*y2-x1*x1-y1*y1))/(2*((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3)));
		double py = ((x1-x2)*(x3*x3+y3*y3-x1*x1-y1*y1)-(x1-x3)*(x2*x2+y2*y2-x1*x1-y1*y1))/(2*((y1-y2)*(x1-x3)-(y1-y3)*(x1-x2)));
		double r  = sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1));
		cout << setprecision(3) << fixed << sisya(px) << " " << setprecision(3) << fixed << sisya(py) << " " << setprecision(3) << fixed << sisya(r) <<endl;
	}
	return 0;
}

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

int main(){
    int n,A,B;
    cin>>n>>A>>B;

    int g=0;//累計合格者数
    int fg=0;//海外の累計合格者数

    char s;
    rep(i,n){
        cin>>s;
        if(s=='a'){
            if(g<(A+B)){
                cout<<"Yes"<<endl;
                g++;
            }else{
                cout<<"No"<<endl;
            }
        }else if(s=='b'){
            if(g<(A+B) && fg<B){
                cout<<"Yes"<<endl;
                g++;
                fg++;
            }else{
                cout<<"No"<<endl;
            }
        }else{//s=="c"
            cout<<"No"<<endl;
        }
    }

}

Measured memory_bytes: 640
while 1:
    n = int(input())
    if n == 0:
        break

    m = [None] * n
    t = [None] * n
    for i in range(n):
        a = int(input())
        m[i] =  t[i] = a
        for j in range(i):
            t[j] += a
            m[j] = max(m[j], t[j])

    print(max(m))

Measured memory_bytes: 7828
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int A, B;
  cin >> A >> B;

  A = (A + 11) % 13;
  B = (B + 11) % 13;

  if (A > B)
    cout << "Alice" << endl;
  else if (A < B)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <deque>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <unordered_map>

using namespace std;
int main(){
    int n,maxx=0;
    vector<string> ans;
    unordered_map<string, int> s;
    cin >> n;
    string mem[n];
    for(int i=0;i<n;i++){
        cin >> mem[i];
        s[mem[i]]++;
        maxx=max(maxx,s[mem[i]]);
    }
    for(int i=0;i<n;i++){
        if(s[mem[i]]==maxx){
            ans.push_back(mem[i]);
            s[mem[i]]=0;
        }
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 28228
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    S = input()
    T = input()
    ans = N*2
    for i in range(N):
        s = S[i:]
        t = T[:N-i]
        if s == t:
            ans -= N-i
            break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
N = int(input())
A = list(int(x) for x in input().split())
mod = 1000000007

rgb = [0,0,0]
sum = 1
for a in A:
    if(rgb.count(a)!=0):
        sum = sum * rgb.count(a) % mod
        rgb[rgb.index(a)]+=1
    else:
        print(0)
        exit()
print(sum)


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> x >> a;
	A = x - a;
	if (A < 0) {
		cout << 0;
	}
	else {
		cout << A;
	}
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
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: 256
#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

void calc(vector< int > &array, map< vector< int >, int > &scan)
{
  queue< vector< int > > que;
  que.emplace(array);
  while(!que.empty()) {
    auto vec = que.front();
    que.pop();
    int dep = scan[vec];
    for(int i = 0; i < array.size(); i++) {
      for(int j = i + 1; j <= array.size(); j++) {
        reverse(begin(vec) + i, begin(vec) + j);
        if(!scan.count(vec)) {
          scan[vec] = dep + 1;
          if(dep + 1 < (array.size() - 1) / 2) que.emplace(vec);
        }
        reverse(begin(vec) + i, begin(vec) + j);
      }
    }
  }
}

int main()
{
  int N;
  cin >> N;
  vector< int > A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    --A[i];
  }
  vector< int > vv(N);
  iota(begin(vv), end(vv), 0);

  map< vector< int >, int > cash1, cash2;
  calc(A, cash1);
  calc(vv, cash2);

  int ret = N - 1;
  do {
    if(cash1.count(vv) && cash2.count(vv))
      ret = min(ret, cash1[vv] + cash2[vv]);
  } while(next_permutation(begin(vv), end(vv)));

  cout << ret << endl;
}

Measured memory_bytes: 66808
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int x;
	cin >> x;
	int val = 100;
	int cnt = 0;
	while (val < x) {
		cnt++;
		val = val + val / 100;
	}
	cout << cnt << endl;
}
int32_t main() {
	BOLT;
	solve();
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] size; // size of subtree, including self
    List<Integer>[] graph;
    long[] dp,ans;
    final long mod = 1000000000+7;
    long[] frac,inv; // inv[i] = the inversion of i! mod M
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
        out.flush();
//        System.out.println(main.solve());
    }
    long solve() throws IOException{
        int n = sc.nextInt();
        size = new int[n]; dp = new long[n]; ans = new long[n];
        graph = new List[n];
        for(int i=0;i<n;i++) graph[i] = new ArrayList<>();
        ini(n+1);
        for(int i=0;i<n-1;i++){
            int a = sc.nextInt()-1, b = sc.nextInt()-1;
            graph[a].add(b); graph[b].add(a);
        }
        dfsSubTree(0,-1);
        ans[0] = dp[0];
        // then tree transform
        for(int to:graph[0]){
            dfsAns(to,0,n);
        }
        for(int i=0;i<n;i++) out.println(ans[i]);
        return 0;
    }
    void dfsSubTree(int root, int from){
        size[root] = 1;
        long base = 1;
        for(int to:graph[root]){
            if(to==from) continue;
            dfsSubTree(to,root);
            size[root] += size[to];
            base = base*dp[to]%mod*inv[size[to]]%mod;
        }
        base = base*frac[size[root]-1]%mod;
        dp[root] = base;
    }
    void dfsAns(int root, int from, int n){
        // to find the final ans of each root. a little bit tricky
        long base = ans[from];
        base = base*inv[n-1]%mod*frac[size[root]]%mod*power(dp[root],mod-2)%mod;
        base = base*frac[n-size[root]-1]%mod;
        base = base*inv[n-size[root]]%mod;
//        base = base*inv[size[root]-1]%mod*dp[root]%mod;
        for(int to:graph[root]){
            if(to==from) continue;
            base = base*dp[to]%mod*inv[size[to]]%mod;
        }
        base = base*frac[n-1]%mod;
        ans[root] = base;
        for(int to:graph[root]){
            if(to==from) continue;
            dfsAns(to,root,n);
        }
    }
    void ini(int n){
        frac = new long[n+1];
        inv = new long[n+1];
        frac[0] = 1; inv[0] = 1; inv[1] = 1;
        for(int i=1;i<=n;i++) frac[i] = i*frac[i-1]%mod;
        inv[n] = power(frac[n],mod-2);
        for(int i=n-1;i>1;i--){
            inv[i] = (i+1)*inv[i+1]%mod;
        }
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
}



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

int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector <ll> p(a), q(b), r(c);
    for(int i = 0; i < a; i++) {
        cin >> p[i];
    }
    sort(p.rbegin(), p.rend());
    for(int i = 0; i < b; i++) {
        cin >> q[i];
    }
    sort(q.rbegin(), q.rend());
    for(int i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(r.rbegin(), r.rend());

    
    ll ans = 0;
    vector <int> v;
    for(int i = 0; i < x; i++) v.push_back(p[i]);
    for(int i = 0; i < y; i++) v.push_back(q[i]);
    for(int i = 0; i < c; i++) v.push_back(r[i]);
    sort(v.rbegin(), v.rend());
    for(int i = 0; i < x+y; i++) ans += v[i];
    cout << ans;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7
const ll mod = 1000000007;

int main() {
    char al;
    cin >> al;
    if (isupper(al)) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h> 
using namespace std;  
#define ll long long int
vector<ll>adj[100005];
vector<ll>vis(100005,false);

void dfs(ll i)
{   
  if(!vis[i]){
    vis[i]=true;
    for(auto it:adj[i])
       dfs(it); 
  }  
}   
int main() 
{ 
        // ll t;
        // cin>>t;
        // while(t--){ 
        ll n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++){
            ll u,v;
            cin>>u>>v;
            u--;
            v--;
            adj[u].push_back(v);
            adj[v].push_back(u);  
        }
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(!vis[i])
             cnt++;
             dfs(i);   
        }
        cout<<cnt-1;
    }

   
   

Measured memory_bytes: 10596
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){
  int w,a,ang=90;
  double x=0,y=0,r;
  while(1){
    scanf("%d,%d",&w,&a);
    if(w==0 && a==0)break;
    r=(double)ang/180.0*M_PI;
    x+=cos(r)*w;
    y+=sin(r)*w;
    ang-=a;
  }
  printf("%d\n%d\n",(int)x,(int)y);
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

ll h[1000005];
ll memo[1000005];
bool check[1000005];


ll dfs(ll index,ll max_h, vector<ll> g[]){
    ll ret = 1;
    REP(i,g[index].size()){
        ll next = g[index][i];
        if(max_h <= h[next])ret = 0;
    }

    return ret;
}

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

    ll n,m;
    cin >> n >> m;
    REP(i,n){
        cin >> h[i];
    }

    vector<ll> g[n];
    REP(i,m){
        ll a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = 0;
    REP(i,n){
        ans += dfs(i,h[i],g);
    }

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

Measured memory_bytes: 10244
#include <stdio.h>
int main() 
{
  int maxv,minv,num,i,R[200000];
  scanf("%d",&num);

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

  minv = R[0];
  maxv = R[1] - R[0];

  for(i=1; i<num; i++){
    if(maxv < R[i] - minv) maxv = R[i] - minv;
    if(minv > R[i]) minv = R[i];
  }

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

  return 0;

}

Measured memory_bytes: 1376
#include<stdio.h>
int main(){
    int n,i,c=0;
    scanf("%d",&n);
    if(n%2==0){
        c=(n/2)-1;
    }
    else{
        for(i=1;i<=(n-1)/2;i++)
            c++;
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int top=0,s[1000];//top为栈顶序号 
void push(int x)//进入栈 
{  s[++top]=x;//top加1之后将元素插入因为需要s[0]为空 
}
int pop()//栈顶元素 
{  top--;
   return s[top+1];
}
int main()
{  int a,b;
   char s[100],c; 
   do
   {  scanf("%s",&s);
      if(s[0]=='+')
      {  a=pop();
         b=pop();
         push(a+b);
      }
      else if(s[0]=='-')
      {  b=pop();//b在a的后面 
         a=pop();
         push(a-b);
      }
      else if(s[0]=='*')
      {  a=pop();
         b=pop();
         push(a*b);
      }
      else push(atoi(s));
   }while((c=getchar())!='\n');
   printf("%d\n",pop());
   return 0;
} 


Measured memory_bytes: 2064
a, b, q = map(int, input().split())
INF = 10 ** 15
s = [-INF] + [int(input()) for _ in range(a)] + [INF] # sorted
t = [-INF] + [int(input()) for _ in range(b)] + [INF] # sorted

from bisect import bisect_left, bisect_right

for _ in range(q):
    x = int(input())
    i = bisect_right(s, x)
    j = bisect_right(t, x)
    d = INF
    for sx in [s[i - 1], s[i]]:
        for tx in [t[j - 1], t[j]]:
            d1 = abs(sx - x) + abs(sx - tx)
            d2 = abs(tx - x) + abs(sx - tx)
            d = min(d, d1, d2)
    print(d)

Measured memory_bytes: 79580
N, K = [int(x) for  x in input().split()]
l = []
for i in range(K):
  d = int(input())
  l2 = [int(x) for x in input().split()]
  for j in range(d):
    if l2[j] not in l:
      l.append(l2[j])
print(N - len(l))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;


signed main(){
    cin>>H>>W;

    int cnt[26]={};
    rep(i,H){
        string s;cin>>s;
        rep(j,W)cnt[s[j]-'a']++;
    }

    int f=0,t=0,o=0;
    rep(i,26){
        f+=cnt[i]/4;
        cnt[i]%=4;
        t+=cnt[i]/2;
        cnt[i]%=2;
        o+=cnt[i];
    }


    int xf=(H/2)*(W/2);
    int xt=(H%2)*(W/2)+(W%2)*(H/2);
    int xo=(H%2)*(W%2);


    if(xf>f){
        cout<<"No"<<endl;
        return 0;
    }
    f-=xf;
    t+=f*2;
    if(xt>t){
        cout<<"No"<<endl;
        return 0;
    }

    if(xo!=o){
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        int max1 = 0, max2 = 0;
        for (int x : a) {
            if (x >= max1) {
                max2 = max1;
                max1 = x;
            } else if (x > max2) max2 = x;
        }
        for (int x : a) {
            out.println(x == max1 ? max2 : max1);
        }
        out.flush();
        out.close();
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }


        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }


        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }
}

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

using namespace std;

int main(){
    
    int n;
    
    cin >> n;
    cout << n << ':';
    int n2=n;
    
    for (int i=2;i*i<=n2;i++){
        
        while (n%i==0){
            
            cout <<' '<< i;
            n/=i;
             
        }

    }
    if(n!=1)cout << ' ' <<n;
    cout << endl;
    
}


Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    UnionFind(int size) : par(size), rank(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

int N, M;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N >> M;

    UnionFind uf(N + M + 2);
    REP(i, N) {
        int K;
        cin >> K;
        REP(k, K) {
            int l;
            cin >> l;
            uf.unite(i, N + l);
        }
    }

    int par = -1;
    REP(i, N) {
        if (par != -1 && par != uf.find(i)) {
            cout << "NO" << endl;
            return 0;
        }
        par = uf.find(i);
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(S: str):
    counter = Counter(S)
    for i in range(ord("a"), ord("z")+1):
        if counter[chr(i)] == 0:
            break
    else:
        print("None")
        return
    print(chr(i))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

int n;
vector<int> d;
int main() {
  cin >> n;
  d.resize(n);
  for(int i = 0; i < n; ++i) cin >> d[i];
  long long ans = 0;
  for(int i = 0; i < n; ++i)
    for(int j = i + 1; j < n; ++j) { ans += d[i] * d[j]; }

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

Measured memory_bytes: 256
#include <stdio.h>


int main(void) {

    int a,b;
    
    scanf("%d %d", &a,&b);
    
    if (a > b) {
        printf("a > b\n");
    } else if (a < b) {
        printf("a < b\n");
    } else {
        printf("a == b\n");
    }    

    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
int main(void)
{
	int a, b, c, d = 0;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b && b == c) {
		d++;
		printf("%d", d);
	}
	else if (a == b || a == c || b == c) {
		d = d + 2;
		printf("%d", d);
	}
	else {
		d = d + 3;
		printf("%d", d);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream> 
using namespace std;
char b;
char a;
int main() {
  cin >> b;
  
  if(b=='A') a = 'T';
  if(b=='G') a = 'C';
  if(b=='C') a = 'G';
  if(b=='T') a = 'A';
  
  cout << a << endl;
  
  return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    vector<string> dp[11];
    dp[1].push_back("a");
    for(int i = 1; i <= 9; i++){
        for(int j = 0; j < dp[i].size(); j++){
            char tail = 'a';
            for(int k = 0; k < dp[i][j].length(); k++){
                tail = max(tail, dp[i][j][k]);
            }
            for(char add = 'a'; add <= tail+1; add++){
                dp[i+1].push_back(dp[i][j]+add);
            }
        }
    }
    sort(dp[N].begin(), dp[N].end());
    rep(i, dp[N].size()) cout << dp[N][i] << "\n";
    return 0;
}

Measured memory_bytes: 11508
def solve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    dic = {"r": P, "s": R, "p": S} #相手の表示に対して出す手の評価値
    T = list(input())
    before = [-1] * (K)
    ans = 0
    for i, j in enumerate(T):
        if not before[i % K] == j:
            before[i % K] = j
            ans += dic[j]
        else:
            before[i%K] = -1
    print(ans)


if __name__ == '__main__':
    solve()


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

int main(){
    int N, M, L=0, R=1e5, lIn, rIn;    
    cin >> N >>M;
    
    for(int i=0; i<M; i++){
	cin >> lIn >>rIn;
	L = max(L, lIn);
	R = min(R, rIn);
    }
    int ans = R-L+1;
    if(ans >=0)
	cout << ans << endl;
    else
	cout << 0 << endl;
}



Measured memory_bytes: 256
from sys import stdin,stdout
from collections import defaultdict
from heapq import heappush, heappop

n, q = map(int,stdin.readline().split())
queries = stdin.readlines()
A = defaultdict(list)
ans = []

#count = 0
for query in queries:
    #print(count)
    #count += 1
    query = query.split()
    if query[0] == '0':
        heappush(A[int(query[1])], -int(query[2]))
    elif query[0] == '1':
        index = int(query[1])
        if len(A[index]) > 0:
            print(-A[index][0])
    else:
        index = int(query[1])
        if len(A[index]) > 0:
            heappop(A[index])



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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  bool test1 = false;
  bool test2 = false;
  REP(i,s.size()){
    if(s[i] == 'C') test1 = true;
    if(test1){
      if(s[i] == 'F') test2 = true;
    }
  }
  Yes(test1 && test2);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
    set<int> X;
    for(int i=0; i<F; i++){
        for(int j=0; j<F; j++){
            int WA = 100 * A * i;
            int WB = 100 * B * j;
            if(WA + WB <= F) X.insert(WA + WB);
        }
    }
    
    set<int> Y;
    for(int i=0; i<F; i++){
        for(int j=0; j<F; j++){
            int SC = C * i;
            int SD = D * j;
            if(SC + SD <= F) Y.insert(SC + SD);
        }
    }
    
    int aw = 100 * A;
    int as = 0;
    
    for(int x:X){
        for(int y:Y){
            if(x + y <= F && y * (aw + as) > as * (x + y) && y * (100 + E) <= E * (x + y)){
                aw = x;
                as = y;
            }
        }
    }
    cout << aw + as << " " << as << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String c = sc.next();
        if(c.charAt(2) == c.charAt(3) && c.charAt(4) == c.charAt(5)){
            System.out.println("Yes");
        } else {System.out.println("No");}
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){

	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<int> a(n);
		for(int i=0;i<n ;i++){
			cin>>a[i];
		}
		sort(a.begin(),a.end());
		int m = 1e9;
		for(int i=0;i<n-1;i++)m = min(m,a[i+1]-a[i]);
		cout<<m<<endl;
	}

	return 0;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int ax = (a > x)? a - x : x - a;
		int bx = (b > x)? b - x : x - b;
		System.out.println((ax < bx)? "A" : "B");
	}
}

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

ll MOD = 1e9 + 7;

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n)
    cin >> a[i];
  vector<ll> c(60);
  rep(i, n)
    rep(j, 60)
      if ((a[i]>>j & 1) == 1)
        c[j]++;
  ll ans = 0;
  ll d = 1;
  rep(i, 60)
  {
    ans = (ans + c[i] * (n - c[i]) % MOD * d % MOD) % MOD;
    d = (d << 1) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
from collections import deque

que = deque()
q = int(input())

for i in range(q):
    query = input().split()

    if query[0] == "0":
        if query[1] == "0":
            que.appendleft(query[2])
        else:
            que.append(query[2])
    elif query[0] == "1":
        print(que[int(query[1])])
    else:
        if query[1] == "0":
            que.popleft()
        else:
            que.pop()


Measured memory_bytes: 34652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, s;
    cin >> n >> s;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> diff(n);
    rep(i,n) diff[i] = abs(x[i] - s);
    int ans = diff[0];
    for(int i = 1; i < n; i++){
        ans = __gcd(ans, diff[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4000
import sys

"""テンプレ"""

# 高速
input = sys.stdin.readline

# 1行を空白でリストにする(int)
def intline():
    return list(map(int, input().split()))


# 上のstrヴァージョン
def strline():
    return list(map(str, input().split()))


# 1列に並んだ数
def intlines(n):
    return [int(input() for _ in range(n))]


# 上の文字列ヴァージョン
def lines(n):
    return [input() for _ in range(n)]
    

"""ここからメインコード"""

k = intline()
k.sort()
 
if [1, 4, 7, 9] == k:
    print("YES")
else:
    print("NO")


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    double ans = 0;
    rep(i, n) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "BTC") x *= 380000.0;
        ans += x;
    }
    cout << fixed << setprecision(5);
    cout << (double)ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  rep(i,365) {
    if (i%26 != 0) cout << i%26<< '\n';
    else cout << 26 << '\n';
  }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010
vll a(mx,0);
ll g(vll &a,ll n,ll x,ll k){
	ll sum=0,b[n];
	rep(i,0,n){sum+=(a[i]%x);b[i]=-1*(a[i]%x);}
	sort(b,b+n);
	// rep(i,0,n)cout<<b[i]<<" ";cout<<"\n";
	if(sum%x==0){
		ll t=sum/x;
		rep(i,0,t)sum+=b[i];
		// cout<<sum<<"\n";
		if(sum<=k)return 1;
	}
	return 0;
}
int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ll p=0;
    rep(i,0,n){ll d;cin>>d;a[i]=d;p+=d;}
	// rep(i,1,20)cout<<f(a,n,i,k)<<" ";cout<<"\n";
	vll f;
	for(ll i=2;i*i<=p;++i){
		if(p%i==0){
			if(i*i==p)f.pb(i);
			else {f.pb(i);f.pb(p/i);}
		}
	}
	f.pb(1);f.pb(p);
	sort(f.begin(),f.end());
	// rep(i,0,f.size())cout<<f[i]<<" ";
	ll m=-1;
	for(ll i=f.size()-1;i>=0;--i){
		if(g(a,n,f[i],k)){cout<<f[i];break;}
	}
	
	return 0;
}



Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

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

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") {
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

struct root {
	int i;
	int value;
};

int main() {
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double o = fabs(((30 * h) + ((m/60) * 30)) - (6 * m));
	long double t = o * (M_PI / 180);
	long double colc = (a * a) + (b * b) - 2 * a * b * cosl(t);
	cout << fixed << setprecision(20) << sqrtl(colc) << endl; 
	return 0;
}

Measured memory_bytes: 4192
import java.util.Scanner;

public class Main {
	private static int[][] rgb;
	private final static char R = 'R';
	private final static char G = 'G';
	private final static char B = 'B';

	public static void main(String[] args) {
		long count = 0;

		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.next());
		String S = in.next();
		in.close();

		rgb = new int[3][2 * N + 1];

		int cntb = 0;
		int cntg = 0;
		int cntr = 0;
		char ch;
		for (int i = N - 1; i >= 0; i--) {
			ch = S.charAt(i);
			if (ch == B) {
				cntb++;
			} else if (ch == G) {
				cntg++;
			} else {
				cntr++;
			}
			rgb[0][i] = cntr; //iも含めて、それ以降のBの数
			rgb[1][i] = cntg; //iも含めて、それ以降のGの数
			rgb[2][i] = cntb; //iも含めて、それ以降のRの数

			//			System.out.println(String.format("rgb[0][%d]:%d, rgb[1][%d]:%d, rgb[2][%d]:%d"
			//					, i, rgb[0][i], i, rgb[1][i], i, rgb[2][i]));
		}

		char ch1, ch2;

		for (int i = 0; i < N - 2; i++) {
			ch1 = S.charAt(i);
			for (int j = i + 1; j < N - 1; j++) {
				ch2 = S.charAt(j);
				if (ch1 == ch2) {
					continue;
				}
				count += calc(i, j, ch1, ch2);
			}
		}
		System.out.println(count);
	}

	public static int calc(int i, int j, char ch1, char ch2) {
		int calc = 0;
		int idx = 2 * j - i;
		if (ch1 == R) {
			if (ch2 == G) { //S_k = Bのものを数える
				calc = rgb[2][j + 1] - (rgb[2][idx] - rgb[2][idx + 1]);
			} else { //S_k = Gのものを数える
				calc = rgb[1][j + 1] - (rgb[1][idx] - rgb[1][idx + 1]);
			}
		} else if (ch1 == G) {
			if (ch2 == R) { //S_k = Bのものを数える
				calc = rgb[2][j + 1] - (rgb[2][idx] - rgb[2][idx + 1]);
			} else { //S_k = Bのものを数える
				calc = rgb[0][j + 1] - (rgb[0][idx] - rgb[0][idx + 1]);
			}
		} else {// ch1 == B
			if (ch2 == R) { //S_k = Gのものを数える
				calc = rgb[1][j + 1] - (rgb[1][idx] - rgb[1][idx + 1]);
			} else { //S_k = Rのものを数える
				calc = rgb[0][j + 1] - (rgb[0][idx] - rgb[0][idx + 1]);
			}
		}
		return calc;
	}
}


Measured memory_bytes: 37540
#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n;
    vector<ll>d(n, 0);
    REP(i, n) cin >> d[i];

    cin >> m;
    vector<ll>t(m, 0);
    REP(i, m) cin >> t[i];

    sort(ALL(d));
    sort(ALL(t));

    int curr = 0;

    REP(i, n){
        if (d[i] == t[curr]){
            curr++;
        }
    }
    if (curr == m){
        cout << "YES" << endl;
        return 0;
    }
    
    cout << "NO" << endl;
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  set<int> se;
  rep(i,n){
    int a;
    cin>>a;
    if(se.count(a)){
      cout<<"NO"<<endl;
      return 0;
    }
    se.insert(a);
  }
  cout<<"YES"<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  vector<ll> dp(50, 1);
  int n = 0;
  fscanf(stdin, "%d", &n);
  for (int i = 2; i <= n; ++i) {
    dp[i] = dp[i - 2] + dp[i - 1];
  }
  fprintf(stdout, "%lld\n", dp[n]);
  return 0;
}

Measured memory_bytes: 1192
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll a, b, h; cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b;
  cin>>a>>b;
  cout<<((a-2*b)>0? a-2*b:0)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
//C - *3 or /2
int main(void){
    int n,a;
    std::cin >> n;
    int ans=0;
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        while(a%2==0){
            ans++;
            a=a/2;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int n,k;
int main(){
	cin >> n >> k;
	string s;
	cin >> s;
	int a[n];
	for(int i = 0;i < n;i++){
		if(s.at(i) == 'L')
			a[i] = 0;
		if(s.at(i) == 'R')
			a[i] = 1;
      	//cout << a[i] << endl;
	}
  	
	int ans = 0;
	vector<int> v;
	int count;
	if(a[0] == 1)
      count = 1;
	else
      count = -1;
	for(int i = 0;i<n-1;i++){
		if(a[i] != a[i+1]){
			v.push_back(count);
			ans += abs(count) - 1;
			if(a[i+1] == 1)
              count = 1;
			else
              count = -1;
		}else{
			if(a[i] == 1)
              count += 1;
			else
              count -= 1;
		}
	}
	v.push_back(count);
  	ans += abs(count) - 1;
	int size = v.size();
  	//cout << ans << endl;
	for(int i = 0;i < k;i++){
		if(size == 1){
			cout << ans << endl;
			return 0;
		}else if(size == 2){
			ans += 1;
			size -= 1;
		}else{
			ans += 2;
			size -= 2;
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 1404
#include<iostream>
#include<cstring>
#include<cstdio>
#include<complex>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll ;
typedef complex<double> cp;
const int Mod=200003;
const int G=2;
int len,bit;
#define Maxn 600010
int rev[Maxn];
cp A[Maxn];

#define pi acos(-1)
void fft(cp A[],int t){
    for(int i=0;i<len;++i)
    if(rev[i]>i)swap(A[rev[i]],A[i]); 
    for(int i=1;i<len;i<<=1){
        cp wn(cos(pi/i),t*sin(pi/i));
        for(int j=0;j<len;j+=i<<1){
            cp w(1,0);
            for(int k=0;k<i;++k){
                cp x=A[k+j];
                cp y=w*A[k+j+i];
                A[j+k]=x+y;
                A[k+j+i]=x-y;
                w=w*wn;
            }
        }
    }
    if(t==-1)
    for(int i=0;i<len;++i)A[i]/=len;
}

int n;
int g[Maxn],to[Maxn];

int main(){
	g[0]=1;
	for(int i=1;i<Mod-1;++i){
		g[i]=2*g[i-1]%Mod;
		to[g[i]]=i;
	}
	ll Ans=0;
	scanf("%d",&n);
	int x;
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		int tmp=1ll*x*x%Mod;
		Ans-=tmp;
		if(!x)continue;
	    x=to[x];
	    A[x]+=cp(1.0,0.0);
	}
	len=1;bit=0;
	while(len<(Mod-1)*2)len<<=1,bit++;
	for(int i=0;i<len;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	fft(A,1);
	for(int i=0;i<len;++i)A[i]=A[i]*A[i];
	fft(A,-1);
	int num=1;
	for(int i=0;i<(Mod-1)*2;++i){
		Ans+=(ll)(A[i].real()+0.5)*num;
		num=2*num%Mod;
	}
	Ans/=2;
	printf("%lld\n",Ans);
    return 0;
}

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

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<int> left(n + 1), right(n + 1);
    for (int i = 0; i < n; i++) left[i + 1] = gcd(left[i], a[i]);
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) right[i + 1] = gcd(right[i], a[i]);
    reverse(right.begin(), right.end());
    int ma = 0;
    for (int i = 0; i < n; i++) {
        ma = max(ma, gcd(left[i], right[i + 1]));
    }
    cout << ma << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;  cin >> n;
    int cnt = 0;
    vector<int> p(n), q(n), base(n);
    rep (i, n) cin >> p[i];
    rep (i, n) cin >> q[i];
    rep (i, n) base[i] = i + 1;
    int a = -1, b = -1;
    do {
        cnt++;
        if (a == -1) {
            bool ok = true;
            rep (i, n) if (base[i] != p[i]) ok = false;
            if (ok) a = cnt;
        }
        if (b == -1) {
            bool ok = true;
            rep (i, n) if (base[i] != q[i]) ok = false;
            if (ok) b = cnt;
        }
    } while (next_permutation(base.begin(), base.end()));

    cout << abs(a - b) << endl;
    
    return 0;
}



Measured memory_bytes: 256