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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll a[3][3];
  bool ab[3][3];
  ll n;
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  rep(i, 3) rep(j, 3) ab[i][j] = false;

  cin >> n;
  ll t;
  rep(i, n) {
    cin >> t;
    rep(i, 3) rep(j, 3) if (a[i][j] == t) ab[i][j] = true;
  }

  if ((ab[0][0] && ab[0][1] && ab[0][2]) ||
      (ab[1][0] && ab[1][1] && ab[1][2]) ||
      (ab[2][0] && ab[2][1] && ab[2][2]) ||
      (ab[0][0] && ab[1][0] && ab[2][0]) ||
      (ab[0][1] && ab[1][1] && ab[2][1]) ||
      (ab[0][2] && ab[1][2] && ab[2][2]) ||
      (ab[0][0] && ab[1][1] && ab[2][2]) || (ab[0][2] && ab[1][1] && ab[2][0]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  // rep(i, 3) {
  //   rep(j, 3) { cout << ab[i][j] ? 1 : 0; }
  //   cout << endl;
  // }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define print(x) cerr <<"\033[1;33m" << x << "\033[0m" << '\n'
#define int long long
#define LL __int128_t
const int xx = 2e5;
const int MOD = 1e9 + 7;

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

  int n;
  cin >> n;
  vector<string>vs(n);
  vector<int>T(n);
  for(int i=0;i<n;i++){
	  cin >> vs[i] >> T[i];
  }
  string X;
  cin >> X;
  
  bool sleep = false;
  int sum = 0;
  for(int i=0;i<n;i++){
	  if(sleep) {
		  sum += T[i];
	  }
	  if(vs[i] == X){
		  sleep = true;
	  }
  }

  cout << sum << '\n';

}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		sc.close();
		ArrayList<Long> pri = new ArrayList<>();
		pri.add(2L);
		for(long k=3; k*k<=n; k+=2) {
			boolean f=true;
			for (Long l : pri) {
				if(l*l>k) {
					break;
				}
				if(k%l==0) {
					f=false;
					break;
				}
			}
			if(f) {
				pri.add(k);
			}
		}
//		out.println(pri.toString());
		long ans=0;
		for (Long l : pri) {
			long cnt=0;
			while(n%l==0) {
				n/=l;
				cnt++;
			}
			if(cnt>0) {
//				out.printf("%d:%d:%d%n", l, cnt, (long)((1+Math.sqrt(1+4*cnt))/2));
				ans+=(long)((-1+Math.sqrt(1+8*cnt))/2);
			}
			if(n==1) break;
		}
//		out.println(n);
		if(n>1) ans++;
		out.println(ans);
	}
}


Measured memory_bytes: 45740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int r;
	cin >> r;
    float ans = M_PI * 2 * r;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
void Google(ll tt){
    cout<<"Case #"<<tt<<": ";
}

int main()
{
    IO
	clock_t begin = clock();
    ll n,k,ss=0;
    cin>>n>>k;
    k*=k;
    for(ll i=0;i<n;i++)
    {
    	ll p,q;
    	cin>>p>>q;
    	ll ans=((p*p)+(q*q));
    	if(ans<=k)
    		ss++;
    }
    cout<<ss;
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:58:04 2019

@author: Yamazaki Kenichi
"""

N = int(input())
S = input()

a,b,c = 0,0,0
flg,flg2 = False,False
for i in range(N):
    if S[i] == '.':
        b += 1
        c = min(c+1, a)
    else:
        a += 1
        c = min(a+1,c)
#    print(a,b,c)
print(min(a,b,c))



Measured memory_bytes: 3500
#include <iostream>

int main(void){
  int n;
  std::cin >> n;
  int val[n];

  long min=999999999999;
  int max=0;
  long profit=-999999999999;

  for(int i=0; i<n; i++){
      std::cin >> val[i];
      if (val[i] < min){ //底値割
        if(i>0 && profit < val[i]-min){
          profit = val[i]-min;
        }
        min = val[i];
      }else if (profit < val[i]-min){
        profit = val[i]-min;
      }
  }
  std::cout << profit << '\n';
  return 0;
}



Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;

signed main() 
{
	int n, semua, atau, dua;
	cin >> n;
	semua = atau = dua  = 1;
	for(int i = 0; i < n; i++)
	{
		semua = (10 * semua + mod)%mod;
		atau = (9 * atau + mod) % mod;
		dua = (8 * dua + mod) % mod;
	}
	cout << ((semua - 2 * atau + mod) % mod + dua + mod) % mod<< '\n';
}

Measured memory_bytes: 3604
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/11.
 */
public class Main {
    public static void main(String[] args) {
        Scanner square = new Scanner(System.in).useDelimiter("\\s");
        int a = square.nextInt();
        int b = square.nextInt();
        System.out.println(a * b + " " + (2 * a + 2 * b));
    }
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1<<18,INF=1<<30;
int ans[MAX];
int N;
string win;

void DFS(vector<int> &S,int bit,int turn){
    if(turn==N){
        ans[bit]=S[0];
        return;
    }
    
    vector<int> T;
    for(int i=0;i<S.size();i+=2){
        int a=S[i],b=S[i+1];
        if(a>b) swap(a,b);
        if(win[b-a-1]=='1'){
            T.push_back(b);
        }else{
            T.push_back(a);
        }
    }
    
    DFS(T,bit,turn+1);
    
    T.clear();
    
    for(int i=1;i<S.size();i+=2){
        int a=S[i],b=S[(i+1)%int(S.size())];
        if(a>b) swap(a,b);
        if(win[b-a-1]=='1'){
            T.push_back(b);
        }else{
            T.push_back(a);
        }
    }
    
    DFS(T,(bit|(1<<turn)),turn+1);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    cin>>win;
    
    vector<int> S((1<<N));
    for(int i=0;i<(1<<N);i++){
        cin>>S[i];
        S[i]--;
    }
    
    DFS(S,0,0);
    
    for(int i=0;i<(1<<N);i++){
        cout<<ans[i]+1<<endl;
    }
}




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

void SolveAndShowEquation(double a,double b,double c,double d,double e,double f);
double Roundoff(double x);
int main(){
  double a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f){
    SolveAndShowEquation(a,b,c,d,e,f);
  }
  return 0;
}

void SolveAndShowEquation(double a,double b,double c,double d,double e,double f){
  double x,y,delta;
  delta=a*e-b*d;
  x=(c*e-b*f)/delta;
  y=(a*f-c*d)/delta;
  x=Roundoff(x);
  y=Roundoff(y);
  cout<<fixed<<setprecision(3)<<x<<" "<<setprecision(3)<<y<<endl;
}

double Roundoff(double x){
  if( x<0 ){
    x*=-1;
    x=double(int(x*1000))/1000+((((x*1000)-int(x*1000))*10)>=5?0.001:0);
    x*=-1;
  }else{
    x=double(int(x*1000))/1000+((((x*1000)-int(x*1000))*10)>=5?0.001:0);
  }
  return x;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if (a1+a2+a3>=22)
	{
		cout << "bust" << endl;
	}
	else
	{
		cout << "win" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def _kosa(a1, a2, b1, b2):
    x1,y1,_ = a1
    x2,y2,_ = a2
    x3,y3,_ = b1
    x4,y4,_ = b2

    tc = (x1-x2)*(y3-y1)+(y1-y2)*(x1-x3)
    td = (x1-x2)*(y4-y1)+(y1-y2)*(x1-x4)
    return tc*td < 0

def kosa(a1, a2, b1, b2):
    return _kosa(a1,a2,b1,b2) and _kosa(b1,b2,a1,a2)


def distance(x1, y1, x2, y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

def distance3(p1, p2, p3):
    x1,y1,_ = p1
    x2,y2,_ = p2
    x3,y3,_ = p3

    ax = x2 - x1
    ay = y2 - y1
    bx = x3 - x1
    by = y3 - y1

    r = (ax*bx + ay*by) / (ax*ax+ay*ay)
    if r <= 0:
        return distance(x1,y1, x3,y3)
    if r >= 1:
        return distance(x2,y2, x3,y3)
    return distance(x1 + r*ax, y1 + r*ay, x3,y3)

def main():
    rr = []

    def f(s):
        def _f(s):
            if '[' in s:
                i = s.index('[')
                c = 1
                for j in range(i+1,len(s)):
                    if s[j] == '[':
                        c += 1
                    elif s[j] == ']':
                        c -= 1
                        if c == 0:
                            return _f(s[:i] + _f(s[i+1:j])[::-1] + s[j+1:])
                return -1
            r = ''
            c = 0
            for t in s:
                if t == '-':
                    c -= 1
                elif t == '+':
                    c += 1
                elif t == '?':
                    r += 'A'
                    c = 0
                else:
                    o = ord(t) - ord('A')
                    o += c
                    o %= 26
                    r += chr(o + ord('A'))
                    c = 0
            return r

        return _f(s)


    while True:
        s = S()
        if s == '.':
            break
        rr.append(f(s))

    return '\n'.join(map(str, rr))



print(main())



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

int main() {
  char a, b, c, d;
  cin >>a >>b >>c >>d ;
  
  if((a =='0'&& b != '0')||(a =='1'&& (b == '1'||b =='2'))){
    if(( c=='0'&& d != '0')||(c =='1'&& (d == '1'||d =='2'))){
      cout <<"AMBIGUOUS" <<endl;
    }
    else{
      cout <<"MMYY" <<endl;
    }
  }
  else{
    if(( c=='0'&& d != '0')||(c =='1'&& (d == '1'||d =='2'))){
      cout <<"YYMM" <<endl;
    }
    else{
      cout <<"NA" <<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    int a = 0, b = 0;
    int max = h * w;
    a = x * w;
    b = (h - x) * y;
    int res = max - (a + b);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a
#define pr2(a,b)    cout<<a<<" "<<b
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


pll P2[MAXN+5];
pll P1[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=oo,x,y,q,c,sum=0,v,t,p;
	// PROCESS IN HERE
	string s;
	sc2(n,s);
	fu(i,1,n-1){
		if(s[i-1]=='W')P1[i].fi=P1[i-1].fi+1,P1[i].se=P1[i-1].se;
		else P1[i].se=P1[i-1].se+1,P1[i].fi=P1[i-1].fi;
	}
	fd(i,n-2,0){
		if(s[i+1]=='W')P2[i].fi=P2[i+1].fi+1,P2[i].se=P2[i+1].se;
		else P2[i].se=P2[i+1].se+1,P2[i].fi=P2[i+1].fi;
	}
	fu(i,0,n-1){
		minize(ans,P1[i].fi+P2[i].se);
	}
	pr(ans);


	re 0;
	// Hack it if you can :)
}

int main(){
//	INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	ll test;
//	sc(test);
//	fu(T,1,test)
	Solves();
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 12948
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  string S,T;
  cin>>S>>T;
  int i =0;
  while(i +T.size() <= S.size()){
    if(T == S.substr(i,T.size())){
      rep(i,S.size()){
        S[i] = S[i] == '?' ? 'a': S[i];        
      }
      print(S);
      return 0;
    }
    i++;
  }
  reverse(ALL(S));
  reverse(ALL(T));
  i = 0;
  while(i +T.size() <= S.size()){
    int idxT = 0;
    FOR(j,i,i+T.size()){
      if(S[j] == T[idxT] || S[j] == '?')idxT++;
      else break;
      if(idxT == T.size()){
        rep(k,S.size()){
          if( i<=k && k-i<T.size() ){S[k]= T[k-i];}
          elif(k != i && S[k] == '?')S[k]='a';
          
        
        }
        reverse(ALL(S));
        print(S);
        return 0;     
      }
    }
    i++;
  }
  print("UNRESTORABLE");
  return 0;
}


Measured memory_bytes: 256
import heapq

N,M = map(int, input().split())
A = list(-int(i) for i in input().split()) 

heapq.heapify(A)

for i in range(M):
    x=heapq.heappop(A)//(-2)
    heapq.heappush(A, -x)

print(-sum(A))



Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int n;
	int ans=0;
	vector<int> a;

	cin>>n;

	for(int i=0;i<2*n;i++){
		int  x;
		cin>>x;
		a.push_back(x);
	}

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


	for(int i=0;i<2*n;i++){
		if(i%2==0){
			ans+=a[i];
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
N,x = map(int,input().split())
if x in {1,2*N-1}:print("No")
else:
    print("Yes")
    if x>=N:
        ans = list(range(N,x))+list(range(x+1,2*N)) + [x] + list(range(1,N))
    else:
        ans = list(range(N+1,2*N)) + [x] + list(range(1,x)) + list(range(x+1,N+1))
    print("\n".join(map(str,ans)))

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

int main()
{
	
	int a, b, c ,x,y,z;
	cin >> a >> b >> c;
	x = a + b;
	y = a + c;
	z = b + c;

	if (x<y&&x<z )
		cout << x;
	else if (y<x  && y<z)
		cout << y;
	else
		cout << z;
		
	
}

Measured memory_bytes: 3572
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created 2017/06/01.
 */
  public class Main {
    public static void main(String[] args) {
      //??\?????¨?????????
      Scanner sc = new Scanner(System.in);
      ArrayList<Integer> ary = new ArrayList<>();

      while (true) {
        int input = Integer.parseInt(sc.next());
        if (input == 0)break;
        ary.add(input);
      }

      for(int i = 0; i < ary.size(); i++){
        System.out.println("Case " + (i+1) + ": " +ary.get(i));
      }

    }
  }

Measured memory_bytes: 42556
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<"="<<x<<endl
const int N=1e6+7;
map<long long,int>q;
map<long long,int>::iterator it ;
long long w[3],p,mx;
int main(){
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		q[a]++;
	}
	it=q.end();
	it--;
	for(it;;it--){
		if(it->second>=2){
			w[p++]=it->first;
			if(p==2)break;
		}
		if(it->second>=4)mx=(it->first)*(it->first);
		if(it==q.begin())break;
	}
	if(mx!=0)p=2;
	if(p!=2)cout<<0<<endl;
	else {
		//de( mx);
		cout<<max( w[0]*w[1],mx)<<endl;
	}
}


Measured memory_bytes: 6528
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val bellman_ford :
    (* 頂点数n *)
    int ->
    (* 辺のリスト
       頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 始点 *)
    int ->
    (* 頂点を受け取り，そこまでの距離を返す関数
       頂点に到達するパスが無ければinfを返し，
       そこに到達するまでに負閉路があればneg_infを返す *)
    (int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    let d = Array.make n Weight.inf in
    (* 始点より終点のインデックスが大きくなる辺を集めた隣接リスト *)
    let inc = Array.make n [] in
    (* 始点より終点のインデックスが小さくなる辺を集めた隣接リスト *)
    let dec = Array.make n [] in
    es.fold (fun ((u, v, _) as e) () ->
      if u <= v
      then inc.(u) <- e :: inc.(u)
      else dec.(u) <- e :: dec.(u)) ();
    d.(s) <- Weight.zero;
    (* 残りの反復回数 *)
    let i = ref n in
    (* 更新が行われたか *)
    let is_modified = ref true in
    (* 各辺の処理 *)
    let f (u, v, c) =
      let open Weight in
      (* 原点から到達できない頂点は更新しない *)
      if 0 < Weight.compare inf d.(u) then
        let dv = if 0 <= Weight.compare neg_inf d.(u) then neg_inf else d.(u) + c in
        if 0 < Weight.compare d.(v) dv then
          (is_modified := true; d.(v) <- if !i <= succ n lsr 1 then neg_inf else dv) in
    while 0 < !i && !is_modified do
      is_modified := false;
      (* インデックスが増加する辺の処理 *)
      for u = 0 to n - 1 do
        List.iter f inc.(u)
      done;
      (* インデックスが減少する辺の処理 *)
      for u = n - 1 downto 0 do
        List.iter f dec.(u)
      done;
      decr i
    done;
    Array.get d
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let inf = min_int
  let neg_inf = max_int
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n m p ->
  let abc = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c - p in
  let d = G.bellman_ford n { G.fold = fun f -> Array.fold_right f abc } 0 (n - 1) in
  if max_int <= d
  then print_endline "-1"
  else Printf.printf "%d\n" @@ max 0 d


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

int main() {
  
  int64_t Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
  
  Q *= 4; H *= 2;
  
  int64_t minL = min(Q, min(H, S));
  
  int64_t withD = N / 2 * D + N % 2 * minL;
  
  int64_t withoutD = N * minL;
  
  cout << min(withD, withoutD) << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> r(n);
  vector<ll> c(n);
  rep(i, n) {
    cin >> r[i] >> c[i];
  }

  // dp[i][j] .. min of dp[i][k] + dp[k+1][j] + r[i]*c[k]*c[j]. (dp[i][j] = 0 if i == j).
  vector<vector<ll>> dp(n, vector<ll>(n, INF));
  rep(i,n) { dp[i][i] = 0; }
  rep(d,n+1) {
    rep(i,n) {
      ll j = i+d-1;
      if (j >= n) { continue; }
      for (ll k = i; k < j; ++k) {
        chmin(dp[i][j], dp[i][k] + dp[k+1][j] + r[i]*c[k]*c[j]);
      }
    }
  }
  // printtree(dp);
  cout << dp[0][n-1] << endl;
}



Measured memory_bytes: 3208
integer,allocatable,dimension(:)::A,B
integer N
integer check
read*,N
allocate(a(N),B(N))
read*,a
b=a
call heapsort(n,b)
check=0
do i=1,N
  if(a(i)==b(i))cycle
  check=check+1 
end do
if(check<=2)then
  print"(A)","YES"
else
  print"(A)","NO"
endif
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll a, v;
    cin >> a >> v;
    ll b, w;
    cin >> b >> w;
    ll t;
    cin >> t;
    ll distance = abs(b - a);
    ll d_p_s = v - w;
    if (distance <= d_p_s * t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

ll f[1000010],finv[1000010];
ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  return (f[n]*finv[n-r]%mod)*finv[r]%mod;
}

ll n;
ll res=0;

int main(){
  cin>>n;
  f[0]=f[1]=1;
  repl(i,1,1000001)f[i+1]=(i+1)*f[i]%mod;
  rep(i,1000001)finv[i]=mod_pow(f[i],mod-2);

  ll res=0;
  ll sum=0;
  repl(i,(n+1)/2,n){
    ll c=((((comb(i-1,n-1-i)*f[i])%mod)*f[n-1-i]%mod)-sum+mod)%mod;
    (res+=c*i%mod)%=mod;
    sum=((comb(i-1,n-1-i)*f[i])%mod)*f[n-1-i]%mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 15872
n = int(input())
adjacents = []
inf =  999999999999999
distances = [inf] * n
colors  = ["white"] * n
from heapq import heappush, heappop

for i in range(n):
  u, k, *a = map(int, input().split())
  adjacents.append([])
  for l in range(k):
    v = a[(l * 2)]
    c = a[(l * 2 + 1)]
    adjacents[u].append([v, c])

def dijkstra(u):
  distances[u] = 0
  queue = []
  heappush(queue, [0, u])

  while queue:
    w, u = heappop(queue)
    
    if distances[u] < w:
      continue
    
    colors[u] = "black"
    distances[u] = w

    for edge, weight in adjacents[u]:
      if colors[edge] != "black" and distances[edge] > weight + w:
        heappush(queue, [weight + w, edge])

dijkstra(0)

for index, edge in enumerate(distances):
  print(index, edge)



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

int main() {
  int n;
  string a;
  cin >> n >> a;
  int count = 0;
  
  for(int i = 0; i < n-2; i++){
    if(a.at(i)=='A' && a.at(i+1)=='B' && a.at(i+2)=='C'){
      count++;
    }
  }
    
    cout << count << endl;
}

Measured memory_bytes: 384
def ss_reverse(ss,a,b):
    rev = ss[a:b+1]
    rev = rev[::-1]
    edited = ss[:a] + rev + ss[b+1:]
    return edited

def ss_replace(ss,a,b,word):
    edited = ss
    edited= ss[:a] + word + ss[b+1:]
    return edited

def print_result(ss,a,b):
    print(ss[a:b+1])

ss = input()
n = int(input())

for i in range(n):
    I = input().split()
    if len(I) == 4:
        ss = ss_replace(ss,int(I[1]),int(I[2]),I[3])
    
    if I[0] == "reverse" :
        ss = ss_reverse(ss,int(I[1]),int(I[2]))

    if I[0] == "print" :
        print_result(ss,int(I[1]),int(I[2]))
    



Measured memory_bytes: 5616
import sys

N,K=(int(x) for x in input().split())

h=[]
for i in range(N):
	h.append(int(input()))	
h.sort()

minimum=10**10
tmp=N-K
for i in range(N-K+1):
	#print("i/minimun,h[i+K-1],h[i]",i,minimum,h[i+K-1],h[i])
	if h[i+K-1]-h[i] < minimum:
		minimum=h[i+K-1]-h[i]

print(minimum)
#print(h)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n, d;
	cin>>n>>d;
	vector<vector<int>> x(n);
	rep(i, n) x[i]=vector<int>(2);
	rep(i, n) cin>>x[i][0]>>x[i][1];

	two_sat ts(n);
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			rep(a, 2) rep(b, 2){
				if(abs(x[i][a]-x[j][b])<d) ts.add_clause(i, 1-a, j, 1-b);
			}
		}
	}

	bool ok=ts.satisfiable();
	if(ok){
		cout<<"Yes"<<endl;
		auto vb=ts.answer();
		rep(i, n) cout<< x[i][vb[i]] <<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3752
n = int(input())
A, B = [], []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

A = A[::-1]
B = B[::-1]

cnt = 0
for i in range(n):
	if (cnt + A[i]) % B[i] == 0:
		continue
	else:
		cnt += B[i] - (cnt + A[i]) % B[i]

print(cnt)

Measured memory_bytes: 58712
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        long N = nextInt();
        long rdN = N / 10 * 10;
        long count = 0;
        for (long i = rdN + 1; i <= N; i++) {
            String si = "" + i;
            long i_fd = Integer.parseInt(si.substring(0, 1));
            long i_ld = Integer.parseInt(si.substring(si.length() - 1, si.length()));
            for (long j = 1; j <= i; j++) {
                String sj = "" + j;
                long j_fd = Integer.parseInt(sj.substring(0, 1));
                long j_ld = Integer.parseInt(sj.substring(sj.length() - 1, sj.length()));
                if (i_fd == j_ld && i_ld == j_fd) {
                    if (i == j) {
                        count++;
                    } else {
                        count += 2;
                    }
                }
            }
        }

        long ans = N < 10 ? count : rdN * rdN / 100 + 8 + count;
        System.out.println(ans);
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }

    public static double nextDouble() throws Exception {
        return Double.parseDouble(nextString());
    }
}

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

int main() {
	// your code goes here
	int n,a,b;
	cin>>n>>a>>b;
	int d=n*a;
	if(d<b)
		cout<<d;
	else if(d>b)
	cout<<b;
	else
	cout<<b;
	return 0;
	
}

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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(abs(a - b) <= k && abs(a-c) <= k && abs(a-d) <= k && abs(a-e) <= k&& abs(b-c) <= k && abs(b-d) <=k && abs(b-e)<=k && abs(c-d) <= k && abs(c-e)<=k && abs(d-e)<=k)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
 
}


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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int x,y,z,K;
LL a[N],b[N],c[N];
int main(){
	ios::sync_with_stdio(false);
	cin>>x>>y>>z>>K;
	priority_queue<LL>q;
	for(int i=1;i<=x;i++)cin>>a[i];
	for(int i=1;i<=y;i++)cin>>b[i];
	for(int i=1;i<=z;i++)cin>>c[i];
	for(int i=1;i<=x;i++){
		for(int j=1;j<=y;j++){
			for(int k=1;k<=z;k++){
				if(q.size()<K)q.push(-(a[i]+b[j]+c[k]));
				else{
					LL now=-q.top();
					if((a[i]+b[j]+c[k])>now)q.pop(),q.push(-(a[i]+b[j]+c[k]));
				}
			}
		}
	}
	vector<LL>ans;
	while(!q.empty()){
		ans.pb(-q.top());
		q.pop();
	}
	reverse(ans.begin(),ans.end());
	for(auto k:ans)cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
typedef long long ll;
ll n, res, a, b, ans;

ll pow(ll x, ll y){
    if (y == 0) return 1;
    return x * pow(x, y - 1);
}

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i <= n; i++) {
        a = i, b = n - i, ans = 0;
        for (ll j = 0; j <= 5; j++) {
            ans += a / pow(9, 5 - j);
            a %= pow(9, 5 - j);
        }
        for (ll j = 0; j <= 6; j++) {
            ans += b / pow(6, 6 - j);
            b %= pow(6, 6 - j);
        }
        res = (i == 0 ? ans : min(res, ans));
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, a, b; cin >> n >> a >> b;
    vector<ll> x(n); REP(i, n) cin >> x[i];

    ll ans = 0;
    REP(i, n-1) {
        ans += min((x[i+1] - x[i]) * a, b);
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		for(int mask = 0 ; mask < (1<<(n - 1)) ; mask++) {
			String temp = "";
			int ret = 0;
			for(int i = n - 1 ; i >= 0 ; i--) {
				if(i == n - 1) {
					temp += s.charAt(n - 1 - i);
					ret += s.charAt(n - 1 - i) - '0';
				} else if((mask&(1<<i)) >= 1) {
					temp += "+" + s.charAt(n - 1 - i);
					ret += s.charAt(n - 1 - i) - '0';
				} else {
					temp += "-" + s.charAt(n - 1 - i);
					ret -= s.charAt(n - 1 - i) - '0';
				}
			}
			if(ret == 7) {
				System.out.println(temp + "=7");
				return;
			}
		}
	}
}

Measured memory_bytes: 21844
# エラトステネスの篩
def Eratosthenes(N):
    ans = [True for i in range(N + 1)]
    ans[0], ans[1] = False, False
    
    for i in range(int(N ** (1 / 2)) + 1):
        if ans[i]:
            for j in range(2 * i, N, i):
                ans[j] = False
    
    return [i for i in range(N + 1) if ans[i]]

# 累積和の前準備
def Cumulative_sum(lists):
    ans = [0]
    for i in lists:
        ans.append(ans[-1] + i)
    return ans

ans = []
while True:
    N = int(input())
    if not N:
        break
    
    prime_sum = Cumulative_sum(Eratosthenes(N + 10))
    left, right = 0, 1
    tmp_ans = 0
        
    while left != right:
        # 一致していた場合
        if prime_sum[right] - prime_sum[left] == N:
            tmp_ans += 1
            right += 1
        # 入力より大きい場合
        elif prime_sum[right] - prime_sum[left] > N:
            left += 1
        # 入力より小さい場合
        else:
            right += 1
    
    ans.append(tmp_ans)    

# 出力
[print(i) for i in ans]
    


Measured memory_bytes: 5852
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    // 1 1 2 2 3 3 6 2  2
    // 1 9 2 8 3 7 6 2
    // 2 2 5
    // 2 5
    int n;
    cin>> n;
    vector<int> ar(n-1);
    for(int i=0;i<n-1;i++)
        cin>>ar[i];
    vector<int> ans(n);
    ans[0]=ar[0];
    ans[n-1]=ar[n-2];
    for(int i=1;i<n-1;i++)
        ans[i]=min(ar[i],ar[i-1]);
    int final_ans=0;
    for(int i=0;i<n;i++)
        final_ans+=ans[i];
    cout<<final_ans;
    return 0;
}
//17:05
//13+5+8+24

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

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

    int n;
    cin >> n;
    string hanako, taro;
    int    pointH = 0, pointT = 0;
    for (int i = 0; i < n; i++) {
        cin >> hanako >> taro;
        if (hanako < taro) {
            pointH += 3;
        } else if (hanako == taro) {
            pointH++;
            pointT++;
        } else {
            pointT += 3;
        }
    }

    cout << pointT << " " << pointH << "\n";

    return 0;
}



Measured memory_bytes: 3224
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();


		//始点から終点。

		int dy=ty-sy;
		int dx=tx-sx;

		putString("U",dy);
		putString("R",dx);

		putString("D",dy);
		putString("L",dx);

		putString("L",1);
		putString("U",dy+1);
		putString("R",dx+1);
		putString("D",1);

		putString("R",1);
		putString("D",dy+1);
		putString("L",dx+1);
		putString("U",1);

	}

	static void putString(String S,int d) {

		for (int i = 0; i < d; i++) {
			System.out.print(S);
		}

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 23236
using System;

class Program
{
    static public void Main(string[] args)
    {
        int[] ans = new int[2] { -1, -1 };

        string input = Console.ReadLine();
        input += '\t';

        if (input[2] == '\t') // |s|==2
        {
            if (input[0] == input[1])
            {
                ans[0] = 1;
                ans[1] = 2;
            }
        }else // |s|!=2
        {
            for(int i = 2; input[i] != '\t'; i++)
            {
                if(input[i]==input[i-1] || input[i] == input[i - 2])
                {
                    ans[0] = i - 1;
                    ans[1] = i + 1;
                    break;
                }
            }
        }
        Console.Write(ans[0]);
        Console.Write(" ");
        Console.WriteLine(ans[1]);
    }
}

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

using namespace std;
using lli = long long int;


int main() {
    std::string s;
    cin >> s;

    lli count = 0;
    char last_color = s[0];
    for (size_t i = 1; i < s.size(); i++) {
        if (last_color == s[i]) {
            s[i] = (s[i] == '1' ? '0' : '1');
            count++;
        }
        last_color = s[i];
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
use std::io;
use std::io::{Read, BufReader};
use std::cmp;

macro_rules! read {
    ( $( $t:ty ),* ) => {
        {
            let mut buf = String::new();
            io::stdin().read_line(&mut buf);
            let mut sp = buf.trim().split(" ");
            ($(
                {
                    sp.next().unwrap().parse::<$t>().unwrap()
                },
            )*)
        }
    }
}
macro_rules! read_vec {
    ($t:ty) => {
        {
            let mut buf = String::new();
            io::stdin().read_line(&mut buf);
            let mut sp = buf.trim().split(" ");
            let mut ret = vec![];
            for s in sp {
                ret.push(s.parse::<$t>().unwrap());
            }
            ret
        }
    }
}

fn main() {
    let n = read!(usize);
    let a = read_vec!(i32);
    
    let mut cnt = vec![0; 101010];
    for v in a {
        cnt[v as usize] += 1;
    }

    let mut ret = 0;
    for i in 1..101000 {
        ret = cmp::max(ret, cnt[i - 1] + cnt[i] + cnt[i + 1]);
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(0, min(b, d) - max(a, c)) << endl;
}

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

int main() {
	int N, K, a = 0;
	string S;
	cin >> N >> K >> S;
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == S[i]) a++;
	}
	cout << min(N - 1, K * 2 + a);
}

Measured memory_bytes: 512
from collections import Counter
N = int(input())
*A, = map(int, input().split())
C = Counter(A)
D = {}
for key in C.keys():
    D[key] = C[key] * (C[key] - 1) // 2
S = sum(D.values())
for k in range(N):
    print(S - C[A[k]] + 1)

Measured memory_bytes: 30776
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
struct c{
  int a;
  int b;
  
  bool operator<( const c& right ) const {
        return b > right.b;
    }
  
};

int main(){
  long long int n,m,i,j,ima=0,wa=0;
  cin>>n>>m;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  vector<c> d(m);
  for(i=0;i<m;i++){
    cin>>d[i].a>>d[i].b;
  }
  sort(d.begin(), d.end());
  for(i=0;i<m;i++){
    for(;;){
      if(a[ima]<d[i].b){
        a[ima]=d[i].b;
      }
      d[i].a--;
      ima++;
      if(d[i].a==0||ima==n){
        break;
      }
    }
    if(ima==n){
      break;
    }
  }
  for(i=0;i<n;i++){
    wa+=a[i];
  }
  cout<<wa;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX


signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	priority_queue<int> Q1;
	priority_queue<int,vector<int>,greater<int>> Q2;
	int Q, query, a, b, c, d;
	int sum = 0, me = 0;
	
	cin>>Q;
	
	for(int i = 0; i < Q; i++){
		cin>>query;
		if(query == 1){
			cin>>a>>b;
			sum += b;
			
			if(Q1.size())c = Q1.top();
			else c = -INF;
			if(Q2.size())d = Q2.top();
			else d = INF;
			
			if(a <= c || Q1.size() == 0){ //cout<<"C"<<endl;
				if(Q1.size()) me += c-a;
				Q1.push(a);
			} else { //cout<<"D"<<endl;
				me += a-c;
				Q2.push(a);
			}
			if(Q1.size() < Q2.size()){ //cout<<"A"<<endl;
				int e = Q1.size()+1, f = Q2.size()-1;
				me += (Q2.top() - Q1.top())*f - (Q2.top() - Q1.top())*e;
				// cout<<Q2.top() - Q1.top()<<" "<<e<<" "<<Q2.top() - Q1.top()<<" "<<f<<"  me "<<me<<endl;;
				Q1.push(Q2.top());
				Q2.pop();
			}
			else if(Q1.size() > Q2.size()+1){ //cout<<"B"<<endl;
				int e = Q1.size()-1, f = Q2.size()+1;
				
				
				Q2.push(Q1.top());
				Q1.pop();
				
				me += (Q2.top() - Q1.top())*e - (Q2.top() - Q1.top())*f;
			}
			
		} else {
			cout<<Q1.top()<<" "<<sum+me<<endl;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 3956