akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int penalty[1000000];
bool vis[1000000];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    int num=0,pen=0;
    while(m--) {
        int x;
        string v;
        cin>>x>>v;
        if (v=="AC") {
            if (!vis[x])num++, pen+=penalty[x];
            vis[x]=1;
        } else {
            if (!vis[x])penalty[x]++;
        }
    }
    cout<<num<<' '<<pen<<endl;
}

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

using namespace std;

int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[0] * a[1] / 2 << endl;
    return 0;
}

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

int main () {
    int N;
    cin >> N;
    vector<int> botan(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
         botan.at(i) = a - 1;
    }
    int sum = 0;
    for (int i = 0; i <= N; i++) {
        sum = botan.at(sum);
        if (sum == 1) {
            cout << i + 1 << endl;
          break;
        }
        else if (i == N) {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var abc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        Array.Sort(abc);
        var result = abc[2] - abc[1];
        var a = result+abc[0];
        result += abc[2]%2!=a%2?1 + (abc[2] + 1 - a) / 2:(abc[2] - a) / 2;
        WriteLine(result);
    }
}


Measured memory_bytes: 13268
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def main():
    s = input()
    t = input()

    for i in range(len(s)):
        if s[i] != t[i]:
            print("No")
            sys.exit()
    print("Yes")
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 9560
def main():
    n,k=map(int,input().split())
    ans=0
    MOD=10**9+7
    l=[0]*(k+1)
    for i in range(1,k+1):
        l[i]=pow(k//i,n,MOD)
    for i in range(k,0,-1):
        x=l[i]
        for j in range(1,k//i):
            x-=l[i*(j+1)]
            x=(x+MOD)%MOD
        l[i]=x
        ans=(ans+i*x)%MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68908
#include<stdio.h>
int main()
{
  int n, rt[200000], i, j, ri = 0, sum = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &rt[i]);
    }
  ri = rt[0];
  sum = rt[1] - ri;
  for(i = 1; i < n; i++)
    {
      if(sum < rt[i] - ri) sum = rt[i] -ri;
      if(ri > rt[i]) ri = rt[i];
    }
  printf("%d\n", sum);
}



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

      int a = sc.nextInt();
      int b = sc.nextInt();

      if (a <= 8 && b <= 8) {
         System.out.println("Yay!");
      }
      else {
         System.out.println(":(");
      }
   }
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main ()
{
	int a, result{0};
	scanf ("%d", &a);
	int b[a];
	for (int i=0; i<a; i++)
	{
		cin>>b[i];
	}
	for (int j=0; j<a; j++)
	{
		if (b[j]!=j+1) result++;
	}
	if (result>2) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;//行列のやつ
const long long  INF = 999999999;
vector<int> p;
vector<vector<int>> dp;
int matrix(){
    int n = p.size()-1;
    for(int i=1;i<=n;i++){
        dp[i][i] = 0;
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j = i+l-1;
            dp[i][j] = INF;
            for(int k=i;k<=j-1;k++){
                int q = dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j];
                dp[i][j] = min(q,dp[i][j]);
            }
        }
    }
    
    return dp[1][n];
}
int main(){
    int n;cin >> n;
    p.resize(n+1);
    dp.assign(n+1,vector<int>(n+1));
    for(int i=0;i<n;i++){
        cin >> p[i] >> p[i+1];
    }
    
    cout << matrix() << endl;
}
/*
 *
 * 連鎖行列積
n 個の行列の連鎖 M1,M2,M3,...,Mn が与えられたとき、スカラー乗算の回数が最小になるように積 M1M2M3...Mn の計算順序を決定する問題を連鎖行列積問題(Matrix-Chain Multiplication problem)と言います。

n 個の行列について、行列 Mi の次元が与えられたとき、積 M1M2...Mn の計算に必要なスカラー乗算の最小の回数を求めるプログラムを作成してください。

入力
入力の最初の行に、行列の数 n が与えられます。続く n 行で行列 Mi(i=1...n) の次元が空白区切りの２つの整数 r、c で与えられます。r は行列の行の数、c は行列の列の数を表します。

出力
最小の回数を１行に出力してください。

制約
*/
/*
1≤n≤100
1≤r,c≤100
入力例 1
6
30 35
35 15
15 5
5 10
10 20
20 25
出力例 1
15125
*/


Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int gcd(int a,int b){
    int r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
int main(){
    int N;
    cin >> N;
    int A[N+100];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int ans=0;
    sort(A,A+N);
    ans = A[0];
    for(int i=1;i<N;i++){
        ans = gcd(ans,A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    int X;
    int[] mem = new int[100010];
    public int calc(int total) {
    	if(total == X)			return 1;		// true
    	if(total > X)			return 0;		// false
    	if(mem[total] != -1)	return mem[total];
    	int ans = 0;
    	for (int i = 100; i <= 105; i++) {
			ans = Math.max(ans, calc(total + i));
		}
    	return mem[total] = ans;
    }
    public void solve() {
    	X = Integer.parseInt(sc.next());
    	Arrays.fill(mem, -1);
    	out.println(calc(0));
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}


Measured memory_bytes: 23252
#include<stdio.h>
#include<stdlib.h>
int main(){
  int h,a,ans;
  scanf("%d %d",&h,&a);
  if(h%a==0){
    printf("%d\n",h/a);
  }
  else{
    printf("%d\n",1+h/a);
  }
  return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, k, ans, sum, last;
Pll a[200001];
struct Edge { LL to, cost; }; 
string str,ss;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i,n) {
		cin >> a[i].fir >> a[i].sec;
		a[i].fir %= a[i].sec;
	}
	Mfor(i, n) {
		ans += (a[i].sec - ((a[i].fir + ans) % a[i].sec))%a[i].sec;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2300
#include <iostream>

using namespace std;

int main() {
	int n;
	while ( cin >> n, n ) {
		int m = 10000, M = 0, sum = 0;
		for (int i = 0; i < n; ++i) {
			int v; cin >> v;
			sum += v;
			m = min(m, v);
			M = max(M, v);
		}
		cout << (sum - m - M) / (n-2) << endl;
	}
}

Measured memory_bytes: 1160
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct Node{
	int value;
	int devid;
	int index;
} arr[100050];
bool comp1(const Node &A,const Node &B)
{
	return A.value<B.value;
}
bool comp2(const Node &A,const Node &B)
{
	return A.index < B.index;
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;++i)
	{
		scanf("%d",&arr[i].value);
		arr[i].index=i;
	}
	sort(arr+1,arr+N+1,comp1);
	for(int i=1;i<=N;++i)
	{
		arr[i].devid=i;
	}
	sort(arr+1,arr+N+1,comp2);
	int B[100050];
	for(int i=1;i<=N;++i)
	{
		B[i]=arr[i].devid;
	}
	int cnt=0;
	for(int i=1;i<=N;++i)
	{
		if(B[i]%2!=i%2)
		{
			cnt++;
		}
	}
	printf("%d",cnt/2);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,x,y;
 	x=0;y=0;
 	char b[100];
 	cin>>a;
 	for(int c=0;c<a;c++)
 	{
 		cin>>b[c];
 	}
 	for(int j=0;j<a;j++)
 	{
 		if(b[j]=='I')
 		x=x+1;
 		if(b[j]=='D')
 		x=x-1;
 		if(x>y)
 		y=x;
 	}
 	cout<<y;
 
return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;

        io.Write(n * (n + 1) / 2);
    }
}

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

const int N = 200005;

const int MOD = 1000000007;

using Sardine = pair<long long, long long>;

int n;
Sardine sar[N];

long long gcd(long long x, long long y) {
  while (y) {
    long long t = x;
    x = y;
    y = t % y;
  }
  return x;
}

long long Abs(long long x) {
  return x < 0 ? -x : x;
}

void simplify(Sardine &s) {
  long long g = gcd(Abs(s.first), Abs(s.second));
  s.first /= g, s.second /= g;
  if (s.second < 0 || (s.second == 0 && s.first < 0)) {
    s.first *= -1;
    s.second *= -1;
  }
}

map<Sardine, int> cnt;

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1LL * ret * x % MOD;
    x = 1LL * x * x % MOD;
  }
  return ret;
}

int solve() {
  scanf("%d", &n);
  int ans = 1;

  int zero = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &sar[i].first, &sar[i].second);
    if (sar[i].first == 0 && sar[i].second == 0) {
      ++zero;
    } else {
      simplify(sar[i]);
      cnt[sar[i]] += 1;
    }
  }

  set<Sardine> s;
  for (int i = 0; i < n; ++i) {
    if (s.find(sar[i]) != s.end()) continue;
    s.insert(sar[i]);
    if (sar[i] == make_pair(0LL, 0LL));
    else {
      Sardine bad = Sardine(sar[i].second, -sar[i].first);
      Sardine bad2 = Sardine(-sar[i].second, sar[i].first);
      if (cnt[bad2] == 0) {
        ans = 1LL * ans * (power(2, cnt[sar[i]]) + power(2, cnt[bad]) - 1) % MOD;
        // cerr << sar[i].first << " " << sar[i].second << " " << ans << endl;
      }
    }
  }

  ans -= 1;
  ans += zero;

  ans %= MOD;
  if (ans < 0) ans += MOD;
  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 56852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e5;
const long inf=1e16;
int main(){
	int N; cin>>N;
	long A[N+1]; cin>>A[0];
	long t[N+1] = {}; t[0] = 1;
	if(A[0] == 1){ cout<<(N == 0 ? 1 : -1)<<endl; return 0; }
	else if(A[0] > 0){ cout<<-1<<endl; return 0; }
	rep(i,1,N+1){
		cin>>A[i];
		if(A[i] <= 2 * t[i-1]){
			t[i] = min(2 * t[i-1] - A[i], inf);
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}//print(A,,N+1);print(t,,N+1);
	long ans = 1;
	long cnt[N+1]; cnt[N] = A[N];
	for(int i = N; i > 0; i--){
		ans += cnt[i];
		cnt[i-1] = A[i-1] + min(cnt[i], t[i-1]);
	}cout<<ans<<endl;//print(cnt,,N+1);
}

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

int main() {

  int N;
  cin >> N;

  string S;
  cin >> S;
  
  int answer = 1;
  char current = S[0];

  for (int i = 0; i < N; i++) {
    if (current != S[i]) {
      current = S[i];
      answer++;
    }
  }

  cout << answer << endl;
  
}

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

pair <int,int> p[100000];
int N,num;
int main(){
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> num;
    p[i] = make_pair(num,i+1);
  }
  sort(p,p+N);
  
  for (int i=0;i<N;i++){
    cout << p[i].second << " ";
  }
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e5 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int__ main()
{	
	int s=6;
	int x; cin >> x; s-= x; cin >> x; s-=x;
	cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int a[n];
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a,a + n);
    long long int Max = a[n - 1];
    long long int r = LLONG_MAX;
    int ans;
    for(int i = n - 2;i >= 0;i--)
    {
        if(fabs(Max / 2.0 - a[i]) < r)
        {
            r = fabs(Max / 2.0 - a[i]);
            ans = a[i];
        }
    }
    cout << Max << " " << ans;

    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  long long int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2==1)
    cout<<b-a<<endl;
  else
    cout<<a-b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  vector<bitset<30>> a_bit(N);
  for (int i=0; i<N; i++) {
    cin >> a[i];
    bitset<30> num(a[i]);
    a_bit[i] = num;
  }
  bitset<30> S = a_bit[0];
  for (int i=1; i<N; i++) S ^= a_bit[i];
  vector<bitset<30>> b(N);
  for (int i=0; i<N; i++) {
    b[i] = S^a_bit[i];
    cout << b[i].to_ullong() << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7860
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
 
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 main():
    n = I()
    a = sorted([sorted(LI()) + [_] for _ in range(n)])
    b = sorted(a, key=lambda x: x[1])
    r = (a[-1][0]-a[0][0]) * (b[-1][1]-b[0][1])
 
 
    bm = b[-1][1] - a[0][0]
    bmi = b[0][2]
    am = a[-1][1]
    at = 0
    k = [[inf,0]]
    for i in range(n-1):
        kk = []
        kk.append(min(k[-1][0], b[i][0], b[i+1][1]))
        kk.append(max(k[-1][1], b[i][0]))
        if kk[0] == k[-1][0]:
            k[-1][1] = kk[1]
        else:
            k.append(kk)
 
    k = k[1:]
    kl = len(k)
 
    am = b[-1][1] - a[0][0]
    ami = a[0][2]
    bm = 0
    mtm = 0
    bt = b[0][1]
 
    for i in range(n-1,0,-1):
        tm = b[i][0]
        if mtm < tm:
            mtm = tm
        if ami == b[i][2]:
            break
        if tm < bt:
            bt = tm
        if tm < b[i-1][1]:
            tm = b[i-1][1]
        bm = mtm
        if tm > bm:
            bm = tm
 
        tr = am * (bm-bt)
        if r > tr:
            r = tr
 
        for j in range(kl):
            ki,km = k[j]
            if km > bm:
                break
            tr = am * (bm-min(ki,bt))
            if r > tr:
                r = tr
 
    return r
 
 
print(main())

Measured memory_bytes: 121176
import sys
sys.setrecursionlimit(1000000)

input = sys.stdin.readline
N, A, B, C = map(int, input().split())
S = [input().strip("\n") for _ in range(N)]
Ans = ["Yes"]
Sn = {"A": 0, "B": 0, "C": 0}

def dfs(i, a, b, c):
    if i == N:
        if min([a, b, c]) >= 0: return True
        else: return False
    if min([a, b, c]) < 0: return False
    
    f, s = S[i][0], S[i][1]
    Ans.append(f)
    if f == "A":
        if s == "B":
            if dfs(i + 1, a + 1, b - 1, c): return True
            else: Ans.pop()

        else:
            if dfs(i + 1, a + 1, b, c - 1): return True
            else: Ans.pop()

    elif f == "B":
        if dfs(i + 1, a, b + 1, c - 1): return True
        else: Ans.pop()

    Ans.append(s)
    if f == "A":
        if s == "B":
            if dfs(i + 1, a - 1, b + 1, c): return True
            else: Ans.pop()

        else:
            if dfs(i + 1, a - 1, b, c + 1): return True
            else: Ans.pop()

    elif f == "B":
        if dfs(i + 1, a, b - 1, c + 1): return True
        else: Ans.pop()

    return False

def solve():
    if dfs(0, A, B, C): print("\n".join(map(str, Ans)))
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

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

int main(void)
{
  	char name[1003];
  	cin.getline(name, 1001);
  	int i=0;
	while(name[i]!='\0')
    {
      i++;
    }
  	if('s'==name[i-1])
    {
      name[i+2]=name[i];  
      name[i]='e';
      	name[i+1]='s';
      	
    }
  	else
    {
     	name[i+1]=name[i];
      name[i]='s';
      
    }

  cout<<name;
      return 0;
}


Measured memory_bytes: 3632
n,m,q=map(int,input().split())
d=[[0]*(n+1) for _ in range(n+1)]
 
for mm in range(m):
  l,r=map(int,input().split())
  d[l][r]+=1

for i in range(n):
  for j in range(n+1):
    d[i+1][j]+=d[i][j]
 
for j in range(n+1):
  for i in range(n):
    d[j][i+1]+=d[j][i]

for qq in range(q):
  x,y=map(int,input().split())
  print(d[y][y]-d[y][x-1]-d[x-1][y]+d[x-1][x-1])

Measured memory_bytes: 14828
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(int i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}
ll h,w;
char grid[1001][1001];
ll dp[1001][1001];
int main()
{
    IOS
    cin>>h>>w;
    
    REP(i,h)
    {
        REP(j,w)
        {
            cin>>grid[i+1][j+1];
        }
    }
    REP(i,h+1)
    {
        REP(j,w+1)
        {
            if(i==1 && j==1)
            {
                dp[i][j] = 1;
                continue;
            }
            if(i==0 || j==0)
            {
                dp[i][j] = 0;
            }
            else
            {
                if(grid[i][j]=='.')
                    dp[i][j] = add(dp[i-1][j],dp[i][j-1]);
                else
                {
                    dp[i][j] = 0;
                }
            }
            // cout<<dp[i][j]<<" ";
        }
        // }cout<<endl;
    }
    cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	if(a<=c&&b<=c)cout<<a+b<<endl;
	else if(b<=a&&c<=a)cout<<b+c<<endl;
	else if(c<=b&&a<=b)cout<<c+a<<endl;
	else if(a<=c&&c<=b)cout<<a+c<<endl;
	else if(b<=a&&a<=c)cout<<a+b<<endl;
	else cout<<c+b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n,l[105];
	cin >> n;
	int m=0,s=0;
	for(int i=0;i<n;i++) {
		cin >>l[i];
		s+=l[i] ;
		if(l[i]>m) m=l[i] ;
	}
	if(2*m<s) cout <<"Yes" ;
	else cout <<"No";
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc126_c
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    double n, k;
    cin >> n >> k;
    double answer = 0.0;
    for (int i = 1; i <= n; i++)
    {
        double this_prob = 1.0 / n;
        int this_score = i;
        while (this_score < k)
        {
            this_score *= 2;
            this_prob /= 2;
        }
        answer += this_prob;
    }
    cout << setprecision(12) << answer << endl;
    // printf("%.12f\n", answer);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  long ver,hor,height;
  while(1){
    cin>>ver>>hor>>height;
    if(!ver && !hor && !height)break;
    int n;
    int dis[3];
    dis[0]=sqrt(ver*ver+hor*hor);
    dis[1]=sqrt(hor*hor+height*height);
    dis[2]=sqrt(height*height+ver*ver);
    cin>>n;
    rep(i,n){
      int r;
      cin>>r;
      int cnt=0;
      rep(i,3){
	if(2*r>dis[i])cnt++;
      }
      if(cnt==0)cout<<"NA"<<endl;
      else cout<<"OK"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
x=int(input())

if(x>=400 and x<=599):
    print('8')
elif(x>=600 and x<=799):
    print('7')
elif(x>=800 and x<=999):
    print('6')
elif(x>=1000 and x<=1199):
    print('5')
elif(x>=1200 and x<=1399):
    print('4')
elif(x>=1400 and x<=1599):
    print('3')
elif(x>=1600 and x<=1799):
    print('2')
elif(x>=1800 and x<=1999):
    print('1')


Measured memory_bytes: 9200
/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-20 16:21:24
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
const int infty = 1000000007;

class BIT
{ // index starts at 1.
public:
  int N;
  ll *data;

  BIT(int n) : N(n)
  {
    data = new ll[N + 1];
    for (auto i = 1; i <= N; ++i)
    {
      data[i] = 0;
    }
  }

  ~BIT()
  {
    delete[] data;
  }

  ll sum(int i)
  { // [1, i]
    ll s = 0;
    while (i > 0)
    {
      s += data[i];
      i -= i & -i;
    }
    return s;
  }

  ll sum(int a, int b)
  { // [a, b)
    return sum(b - 1) - sum(a - 1);
  }

  void add(int i, ll x)
  {
    while (i <= N)
    {
      data[i] += x;
      i += i & -i;
    }
  }

  void add(int i)
  {
    add(i, 1);
  }
};

char c[4020];
int a[4020];
int cost[2][2010][2010];
int DP[2010][2010];

int main()
{
  int N;
  cin >> N;
  for (auto i = 0; i < 2 * N; i++)
  {
    cin >> c[i] >> a[i];
  }
  BIT bit[2] = {BIT(N), BIT(N)};
  reverse(c, c + 2 * N);
  reverse(a, a + 2 * N);
  fill(&cost[0][0][0], &cost[0][0][0] + 2 * 2010 * 2010, -1);
  for (auto l = 0; l < 2 * N; l++)
  {
    int k = (c[l] == 'B');
    int i = a[l];
    bit[k].add(i);
    // cerr << "bit[" << k << "].add(" << i << ")" << endl;
    if (k == 0)
    {
      for (auto j = 0; j <= N; j++)
      {
        cost[k][i - 1][j] = bit[0].sum(i - 1) + bit[1].sum(j);
      }
    }
    else
    {
      for (auto j = 0; j <= N; j++)
      {
        cost[k][j][i - 1] = bit[1].sum(i - 1) + bit[0].sum(j);
      }
    }
  }
  DP[0][0] = 0;
  for (auto i = 0; i <= N; i++)
  {
    for (auto j = 0; j <= N; j++)
    {
      if (i == 0 && j == 0)
      {
        DP[i][j] = 0;
        continue;
      }
      DP[i][j] = infty;
      if (i > 0)
      {
        assert(cost[0][i - 1][j] >= 0);
        DP[i][j] = min(DP[i][j], DP[i - 1][j] + cost[0][i - 1][j]);
      }
      if (j > 0)
      {
        assert(cost[1][i][j - 1] >= 0);
        DP[i][j] = min(DP[i][j], DP[i][j - 1] + cost[1][i][j - 1]);
      }
    }
  }
  cout << DP[N][N] << endl;
  return 0;
}


Measured memory_bytes: 47616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  std::cin >> x>>y>>z>>w;
  for(;;){
    z-=y;
    if(z<1){
      std::cout << "Yes" << '\n';
      return 0;
    }
    x-=w;
    if(x<1){
      std::cout << "No" << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
long F[10];
void calc(){
	F[0] = F[1] = 1;
	rep(i,2,10) F[i] = F[i-1] + F[i-2];
	return;
}
int main(){//gengo kakunin
	int H,W,K;cin>>H>>W>>K;
    calc();
	long dp[H+1][W] = {}; dp[0][0] = 1;
	rep(i,1,H+1){
		rep(j,0,W){
			long res = 0;
            res += dp[i-1][j] * F[j] * F[W-j-1] % mod;
			if(j > 0) res += dp[i-1][j-1] * F[j-1] * F[W-j-1] % mod;
			if(j < W-1) res += dp[i-1][j+1] * F[j] * F[W-j-2] % mod;
			dp[i][j] = res % mod;
		}
	}cout<<dp[H][K-1]<<endl;//pprint(dp,,H+1,W);
}

Measured memory_bytes: 256
class _Dice:
    
    def __init__(self, nums):
        self.nums = list(nums)
        
    @property
    def top(self):
        return self.nums[0]
        
    def _shift(self, *pairs):
        for pair in pairs:
            num = self.nums[pair[0]]
            self.nums[pair[0]] = self.nums[pair[1]]
            self.nums[pair[1]] = num
            
    def get_matches(self, num):
        return [i for i, m in enumerate(self.nums) if m == num]
            
    def go(self, opes:str):
        for ope in opes:
            if ope == "N":
                self.go_north()
            elif ope == "E":
                self.go_east()
            elif ope == "W":
                self.go_west()
            else:
                self.go_south()
                
    def go_top(self, index):
        
        if index == 1:
            self.go_north()
        elif index == 2:
            self.go_west()
        elif index == 3:
            self.go_east()
        elif index == 4:
            self.go_south()
        elif index == 5:
            self.go_north()
            self.go_north()
            
    def go_ahead(self, index):

        if index == 2:
            self.go_cw()
        elif index == 4:
            self.go_cw()
            self.go_cw()
        elif index == 3:
            self.go_ccw()
            
        
    def go_north(self):
        self._shift((0, 1), (1, 5), (5, 4))
        
    def go_east(self):
        self._shift((0, 3), (3, 5), (5, 2))
        
    def go_west(self):
        self._shift((0, 2), (2, 5), (5, 3))
        
    def go_south(self):
        self._shift((0, 4), (4, 5), (5, 1))
        
    def go_ccw(self):
        self._shift((3, 4), (4, 2), (2, 1))
        
    def go_cw(self):
        self._shift((3, 1), (1, 2), (2, 4))
        
        
class Dice(_Dice):
    
    @classmethod
    def isequal(cls, a:_Dice, b:_Dice):
                
        a_clone = a.nums.copy()
        for top in a.get_matches(b.nums[0]):
            a.go_top(top)
            a_top_clone = a.nums.copy()
            for ahead in a.get_matches(b.nums[1]):
                a.go_ahead(ahead)
                
                for i, j in zip(a.nums, b.nums):
                    if i != j:
                        break
                else:
                    return True
                
                a.nums = a_top_clone.copy()
                
            a.nums = a_clone.copy()
            
        else:
            return False
        
def check(dices):
    for i, dice_A in enumerate(dices):
        if i == len(dices) - 1:
            break
        
        for dice_B in dices[i + 1:]:
            if Dice.isequal(dice_A, dice_B):
                return False
        
    return True
        

count = int(input())
dices = [Dice(map(int, input().split())) for _ in range(count)]
print("Yes" if check(dices) else "No")


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

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

    if (n < 10){
        cout << n << endl;
    }
    else if (n < 100){
        cout << 9 << endl;
    }
    else if (n < 1000){
        cout << n - 100+ 1 + 9 << endl;
    }
    else if (n < 10000){
        cout << 909 << endl;
    }
    else if (n < 100000){
        cout << n - 10000 + 1 + 909 << endl;
    }
    else{
        cout << 90909 << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	if (s.size() <= 5)cout << "INVALID\n";
	else{
		bool n = false, c = false, sm = false;
		for (int i = 0; i < s.size(); i++){
			if (s[i] == '0')n = true; else if (s[i] == '1')n = true;
			else if (s[i] == '2')n = true; else if (s[i] == '3')n = true;
			else if (s[i] == '4')n = true; else if (s[i] == '5')n = true;
			else if (s[i] == '6')n = true; else if (s[i] == '7')n = true;
			else if (s[i] == '8')n = true; else if (s[i] == '9')n = true;
			else if (s[i] == 'a')c = true; else if (s[i] == 'b')c = true;
			else if (s[i] == 'c')c = true; else if (s[i] == 'd')c = true;
			else if (s[i] == 'e')c = true; else if (s[i] == 'f')c = true;
			else if (s[i] == 'g')c = true; else if (s[i] == 'h')c = true;
			else if (s[i] == 'i')c = true; else if (s[i] == 'j')c = true;
			else if (s[i] == 'k')c = true; else if (s[i] == 'l')c = true;
			else if (s[i] == 'm')c = true; else if (s[i] == 'n')c = true;
			else if (s[i] == 'o')c = true; else if (s[i] == 'p')c = true;
			else if (s[i] == 'q')c = true; else if (s[i] == 'r')c = true;
			else if (s[i] == 's')c = true; else if (s[i] == 't')c = true;
			else if (s[i] == 'u')c = true; else if (s[i] == 'v')c = true;
			else if (s[i] == 'w')c = true; else if (s[i] == 'x')c = true;
			else if (s[i] == 'y')c = true; else if (s[i] == 'z')c = true;
			else if (s[i] == 'A')sm = true; else if (s[i] == 'B')sm = true;
			else if (s[i] == 'C')sm = true; else if (s[i] == 'D')sm = true;
			else if (s[i] == 'E')sm = true; else if (s[i] == 'F')sm = true;
			else if (s[i] == 'G')sm = true; else if (s[i] == 'H')sm = true;
			else if (s[i] == 'I')sm = true; else if (s[i] == 'J')sm = true;
			else if (s[i] == 'K')sm = true; else if (s[i] == 'L')sm = true;
			else if (s[i] == 'M')sm = true; else if (s[i] == 'N')sm = true;
			else if (s[i] == 'O')sm = true; else if (s[i] == 'P')sm = true;
			else if (s[i] == 'Q')sm = true; else if (s[i] == 'R')sm = true;
			else if (s[i] == 'S')sm = true; else if (s[i] == 'T')sm = true;
			else if (s[i] == 'U')sm = true; else if (s[i] == 'V')sm = true;
			else if (s[i] == 'W')sm = true; else if (s[i] == 'X')sm = true;
			else if (s[i] == 'Y')sm = true; else if (s[i] == 'Z')sm = true;
			if (n == true && c == true && sm == true) {
				cout << "VALID\n";
				goto Exit;
			}
		}
		cout << "INVALID\n";
	Exit:;
	}
	char c; cin >> c;
}

Measured memory_bytes: 3204
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, K = lr()
SX, SY, GX, GY = lr()
SX -= 1; SY -= 1; GX -= 1; GY -= 1
pond = [sr() for _ in range(H)]
INF = 10 ** 10

def to_ID(x, y, con):
    return (x*W + y) * 4 + con

def mod_ceil_K(x):
    return (x+K-1) // K * K

def push(d, id):
    if dist[id] < d:
        return
    dist[id] = d
    heappush(que, (d, id))    

dist = [INF] * (H*W*4)
start = to_ID(SX, SY, 0)
dist[start] = 0
que = [(0, start)]
UDLR = [(0, -1), (1, 0), (0, 1), (-1, 0)]
goal = to_ID(GX, GY, 0)
while que:
    d, id = heappop(que)
    if id == goal:
        answer = mod_ceil_K(d) // K
        print(answer); exit()
    if dist[id] < d:
        continue
    x = id // 4 // W
    y = id // 4 % W
    con = id % 4
    for i in range(4):
        next_id = to_ID(x, y, i)
        if dist[next_id] > mod_ceil_K(d):
            push(mod_ceil_K(d), next_id)
    dx = UDLR[con][0]; dy = UDLR[con][1]
    nx = x + dx; ny = y + dy
    if not (0 <= nx < H and 0 <= ny < W) or pond[nx][ny] == '@':
        continue
    next_id = to_ID(nx, ny, con)
    if dist[next_id] > d + 1:
        dist[next_id] = d + 1
        push(d+1, next_id)
    
print(-1)

Measured memory_bytes: 222800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int k;
  cin >> k;
  cout << k/2*(k-k/2) << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

ll mod;

void mul_mod(ll& a, ll b){
	a *= b;
	a %= mod;
}

void add_mod(ll& a, ll b){
	b += mod;
	a += b;
	a %= mod;
}

vector<int> g[100100];

int d[100100],pr[100100];
ll memo[100100],calc[100100];
bool done[100100];

ll treedp(int v, int p){
	int i;
	ll t=1ll;
	if(!(d[v]<0)){
		return memo[v];
	}
	d[v] = d[p]+1;
	pr[v] = p;
	for(i=(g[v].l_ength()-1); i>=0; --i){
		if(g[v][i] == p){
			continue;
		}
		calc[g[v][i]] = t;
		mul_mod(t,(treedp(g[v][i],v)+1)%mod);
		mul_mod(memo[v],(treedp(g[v][i],v)+1)%mod);
	}
	t = 1ll;
	for(i=0; i<g[v].l_ength(); ++i){
		if(g[v][i] == p){
			continue;
		}
		mul_mod(calc[g[v][i]],t);
		mul_mod(t,(treedp(g[v][i],v)+1)%mod);
	}
	return memo[v];
}

ll solve(int v){
	if(done[v]){
		return calc[v];
	}
	done[v] = true;
	if(v == 0){
		calc[v] = 0ll;
		return calc[v];
	}else if(pr[v] == 0){
		return calc[v];
	}
	mul_mod(calc[v],(solve(pr[v])+1)%mod);
	return calc[v];
}

int main(void){
	int n,i,j,x,y;
	fill(d,d+100100,-1);
	fill(memo,memo+100100,1ll);
	fill(done,done+100100,false);
	cin >> n >> mod;
	for(i=1; i<n; ++i){
		cin >> x >> y;
		--x; --y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	treedp(0,n);
	for(i=0; i<n; ++i){
		cout << ((treedp(i,pr[i])*(solve(i)+1)%mod)%mod) << endl;
	}
	return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  int ans=1,a=0;
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    a+=b;
    if(x>=a){ans++;}else{break;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]<<" ";
    for(i=0;2*a[i]<a[n-1];){i++;}
    int c=2*a[i]-a[n-1], b=a[n-1]-2*a[i-1];
    if(c<b) cout<<a[i];
    else cout<<a[i-1];
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(K: int, A: int, B: int):
    for x in range(A, B+1):
        if x % K == 0:
            print("OK")
            return
    print("NG")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(K, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N), dx(N);
  for (int i=0; i<N; i++) {
    cin >> x[i];
  }
  x.push_back(X);
  int mdx=1000000001;
  sort(x.begin(), x.end());
  for (int i=0; i<N; i++) {
    dx[i]=x[i+1]-x[i];
    mdx=min(mdx, dx[i]);
  }
  
  int M=1;
  priority_queue<int,vector<int>, greater<int>> Q;
  
  if (dx.size()==1) {
    M=dx[0];
    goto OUT;
  }
  
  for (int i=2; i<=mdx; i++) {
    if (mdx%i==0) {
      Q.push(i);
    }
  }
  
  while (Q.size()>0) {
    int q=Q.top();
    Q.pop();
    while (true) {
      int fin=0;
      for (int i=0; i<N; i++) {
        if (dx[i]%q!=0) {
          fin=1;
          break;
        }
      }
      if (fin==1) {break;}
      for (int i=0; i<N; i++) {
        dx[i]/=q;
      }
      M*=q;
    }
  }
OUT:
  cout << M << endl;
}


Measured memory_bytes: 4584
check=0
K=int(input())
A,B = (int(x) for x in input().split())
if (A>=K and A%K == 0) or (B>=K and B%K==0):
    print('OK')
elif B-A>=K:
    print('OK')
else:
    for i in range(A,B+1,1):
        if i%K == 0:
            check=1
            break
    if check == 1:
        print('OK')
    else:
        print('NG')

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1)
#define nui 100
#define INF 100000000000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define F(i,a,n) for(ll i=a;i<n;i++)
#define B(i,a,n) for(ll i=n-1;i>=a;i--)
#define tc int t;cin>>t;while(t--)
#define tcf int t;cin>>t;for(int w=1;w<=t;w++)



using namespace std;

void dex(int a)
{
    if (a == 1)
    {
        cout << "1\n";
    }
    else if (a == -1)
    {
        cout << "-1\n";
    }
    else if (a == 0)
    {
        cout << "0\n";
    }
    else if (a == 2)
    {
        cout << "YES\n";
    }
    else if (a == 3)
    {
        cout << "NO\n";
    }

}

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




int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    ll csum = 0;
    F(i, 0, n)
    {
        cin >> a[i];
        sum += a[i];
        csum += (a[i] % mod) * (a[i] % mod);
        csum %= mod;
        sum %= mod;
    }
    sum = ((sum % mod) * (sum % mod)) % mod;
    cout << ((mod + sum - csum) * binpow(2, mod - 2) ) % mod << "\n";




    return 0;

}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout << (a-1,b-1)*(b-1,a-1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    double p[n];
    rep(i,0,n)cin>>p[i];

    double dp[n+1][n+1];
    dp[0][0]=1;
    rep(i,0,n+1)
    {
        rep(j,1,n+1)
        {
            if(j>=i)
            {
                if(i==0 && j>=1)
                {
                    dp[i][j]=dp[i][j-1]*(1-p[j-1]);
                }
                else if(j==i) dp[i][j]=dp[i-1][j-1]*p[j-1];
                else
                {
                    dp[i][j]=p[j-1]*dp[i-1][j-1] + (1-p[j-1])*dp[i][j-1];
                }
            }
            else dp[i][j]=0;
           // cout<<dp[i][j]<<" ";
        }
      //  cout<<'\n';
    }
    double ans=0;
    rep(i,n/2+1,n+1) ans+=dp[i][n];
    cout<<fixed<<setprecision(10)<<ans;

    return 0;
}



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

bool solve() {
    int N;
    cin >> N;

    if(!N) return false;

    int cnt[26] = {};

    bool suc = false;
    vector<char> vc(N);
    for(auto &e : vc) cin >> e;

    for(int i = 0; i < N; i++) {
        char c = vc[i];
        cnt[c - 'A']++;
        int rest = N - 1 - i;
        auto ptr = max_element(cnt, cnt + 26);
        int cand = ptr - cnt;
        bool ok = true;
        for(int j = 0; j < 26; j++) {
            if(j == cand) continue;
            int tmp = cnt[j] + rest;
            if(tmp >= *ptr) ok = false;
        }
        if(ok) {
            suc = true;
            cout << (char)('A' + cand) << ' '  << i + 1 << endl;
            break;
        }
    }
    if(!suc) cout << "TIE" << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3004
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut dp = vec![vec![vec![0; 1500 + 1]; 55]; 55];
    dp[0][0][0] = 1;
    let big_int = 1000_000_000 + 7;
    for i in 0..n {
        for j in 0..i + 1 {
            for ki in 0..k / 2 + 1 {
                // a) connect both
                dp[i + 1][j][ki + j] += dp[i][j][ki];
                dp[i + 1][j][ki + j] %= big_int;
                // b) both wait
                dp[i + 1][j + 1][ki + j + 1] += dp[i][j][ki];
                dp[i + 1][j + 1][ki + j + 1] %= big_int;
                // c)
                dp[i + 1][j][ki + j] += dp[i][j][ki] * 2 * j;
                dp[i + 1][j][ki + j] %= big_int;
                // d)
                if j > 0 {
                    let x = (j * j) % big_int;
                    dp[i + 1][j - 1][ki + j - 1] += dp[i][j][ki] * x;
                    dp[i + 1][j - 1][ki + j - 1] %= big_int;
                }
            }
        }
    }
    if k % 2 == 1 {
        println!("{}", 0);
    } else {
        println!("{}", dp[n][0][k / 2]);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++)
        cin >> d[i];
    int ret = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ret += (d[i] * d[j]);
        }
    }
    cout << ret;
}

Measured memory_bytes: 256