akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int x,y,box;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0)break;
        if(x>y){
            box=x;
            x=y;
            y=box;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1796
// YOU THINK YOU KNOW ME.//


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int                      long long
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define countbit                __builtin_popcount
#define loop(i,a,n)				for(int i=a;i<n;i++)
#define pb                      push_back
#define pf                      push_front
#define mp                      make_pair
#define f                       first
#define s                       second
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define boost                   ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
#define cases                   int tests;cin>>tests;while(tests--)
#define all(s)                  s.begin(),s.end()
#define line                    cout<<endl;
#define watch(x)                cout<<(#x)<<" is "<<x<<endl
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rich_set;
bool isprime(int n){if(n==1)return false;if(n==2)return true;for(int i=2;i<=sqrt(n);i++){if(n%i==0){ return false;}}return true;}
int poww(int b,int e){if(e==0)return 1;else if(e%2==0){int a=pow(b,e/2);return a*a;}else {int a=pow(b,e/2);return b*a*a;}}
int powm(int x,int y,int m=MOD){x=x%m;int res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
int modInverse(int a, int m=MOD) { return powm(a, m-2, m);}
void print(vector<int>v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}}
void print(int arr[]){int size = *(&arr + 1) - arr; for(int i=0;i<size;i++){cout<<arr[i]<<" ";}}
string to_bin(int n){string res="";int i=0;while(n>0){if(n%2==1){res=res+'1';}else{res=res+'0';}n/=2;i++;}reverse(all(res));return res;}
int to_dec(string s){int n=s.size(),ans=0,temp=1;for(int i=n-1; i>=0; i--){int x=s[i]-'0';ans+=x*temp;temp*=2;}return ans;}
void result(bool f){if(f)cout<<"YES"<<endl;else cout<<"NO"<<endl;}



void solve(){
	int n,m;
    cin>>n>>m;
    int dp[n+1][m+1];
    string mat[n+1];
    loop(i,0,n){
        cin>>mat[i];
    }
    bool f=0;
    
    loop(i,0,n){
        loop(j,0,m){
            dp[i][j]=0;
        }
        
    }
    dp[0][0]=1;
    loop(i,0,n){
        loop(j,0,m){
            if(mat[i][j]=='#'){
                dp[i][j]=0;
                continue;
            }
            if(i==0 && j==0){
                dp[i][j]=1;
            }
            else if(i==0){
               
                    dp[i][j]=dp[i][j-1];
                     if(mat[i][j]=='#')dp[i][j]=0;
            }
            else if(j==0){
                dp[i][j]=dp[i-1][j];
                 if(mat[i][j]=='#')dp[i][j]=0;
            }
            else if(mat[i][j]=='.')
            dp[i][j]= dp[i-1][j] + dp[i][j-1];
            
            
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[n-1][m-1]<<endl;

}
int32_t main(){
	boost
  //cases
	solve();	
	
	//return 0;
}

Measured memory_bytes: 9088
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
pre = a[0]
for ai, bi in zip(a[1:], b):
    if pre <= bi:
        ans += pre
        bi -= pre
    else:
        ans += bi
        bi = 0
    pre = ai
    if pre <= bi:
        ans += pre
        pre = 0
    else:
        ans += bi
        pre -= bi
print(ans)


Measured memory_bytes: 18476
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

set<int>a[200],b[200];

int main(void){
    ll q,h,s,d;
    ll n;
    cin>>q>>h>>s>>d;
    cin>>n;
    ll min1=min(4*q,min(2*h,s));
    ll min2=min(8*q,min(4*h,min(2*s,d)));
    cout<<(n/2)*min2+(n%2)*min1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
string s;
cin >> s;
int zero =0,iti=0;
for(int i=0;i<s.size();i++){
    if(s.at(i)=='0')zero++;
    else iti++;
}
cout << min(zero,iti)*2<<endl;
 }


Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b;

	cin >> a >> b;
	
	cout << (a - 1) * (b - 1) << endl;

}

Measured memory_bytes: 256
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <random>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	int n, m;
	cin >> n >> m;
	COUT((m - 1)*(n - 1));
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 256
import collections


def main():
    n, m = map(int, input().split())

    streets = collections.defaultdict(list)

    for i in range(m):
        a, b = map(int, input().split())
        streets[a].append(b)
        streets[b].append(a)

    for i in range(1, n + 1):
        print(len(streets[i]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
from collections import deque
from heapq import heappush, heappop, heapify
sys.setrecursionlimit(10**6)

def main():
    T = int(input())
    for ti in range(T):
        ans = 0
        N = int(input())
        L,R = [],[]
        for _ in range(N):
            k,l,r = map(int,input().split())
            ans += min(l,r)
            if l > r:
                L.append((l-r,k))
            elif l < r:
                if N-k > 0:
                    R.append((r-l,N-k))
        L.sort(key=lambda x: x[1])
        R.sort(key=lambda x: x[1])
        LC = deque(L)
        RC = deque(R)

        H = []
        for i in range(1,N+1):
            while LC and LC[0][1] == i:
                heappush(H, LC.popleft())
            while len(H) > i:
                heappop(H)
        while H:
            ans += heappop(H)[0]

        H = []
        for i in range(1,N+1):
            while RC and RC[0][1] == i:
                heappush(H, RC.popleft())
            while len(H) > i:
                heappop(H)
        while H:
            ans += heappop(H)[0]
        
        print(ans)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 37308
import java.util.Scanner;

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(":(");
    }else{
      System.out.println("Yay!");
    }

  }
}

Measured memory_bytes: 21716
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
q = int(input())
cnt_A = dict(Counter(A))
ans = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b in cnt_A and cnt_A[b] > 0:
        count = cnt_A[b]
        cnt_A[b] = 0
        if c not in cnt_A:
            cnt_A[c] = count
        else:
            cnt_A[c] += count
        ans += ((c - b) * count)
    print(ans)

Measured memory_bytes: 21296
import sys

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_max = max(x)
y_min = min(y)

if(x_max >= y_min):
    print("War")
    sys.exit()
elif(X >= Y):
    print("War")
    sys.exit()

for i in range(x_max + 1, y_min + 1):
    if(i > X and i <= Y):
        print("No War")
        sys.exit()
print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  vector<ll> a(200000);
  vector<ll> b(200000);
  vector<ll> c(200000);
  rep(i,n){
    cin>>a[i+1]>>b[i+1]>>c[i+1];
  }

  ll ans[200000][3];
  ans[1][0]=a[1];
  ans[1][1]=b[1];
  ans[1][2]=c[1];
  for(ll i=2;i<=n;i++){
    chmax(ans[i][0],ans[i-1][1]+a[i]);
    chmax(ans[i][0],ans[i-1][2]+a[i]);
    chmax(ans[i][1],ans[i-1][0]+b[i]);
    chmax(ans[i][1],ans[i-1][2]+b[i]);
    chmax(ans[i][2],ans[i-1][0]+c[i]);
    chmax(ans[i][2],ans[i-1][1]+c[i]);
  }

  cout << max({ans[n][0],ans[n][1],ans[n][2]}) << endl;
}


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

int main() {
  long long N, M;
  cin >> N >> M;
  
  if( N == 1 && M == 1 ){
    cout << 1 << endl;
    return 0;
  }
  else if ( (N == 1 && M != 1) || (N != 1 && M == 1)){
    cout << max(N, M) - 2 << endl;
    return 0;
  }
  else cout << (N - 2)*(M - 2) << endl;
  
}

Measured memory_bytes: 256
monsterAHP, monsterAAttack, monsterBHP, monsterBAttack = map(int, input().split(' '))
turnA = int(monsterBHP / monsterAAttack)
modA = monsterBHP % monsterAAttack
turnB = int(monsterAHP / monsterBAttack)
modB = monsterAHP % monsterBAttack

if(modA != 0):
  turnA = turnA + 1
  
if(modB != 0):
  turnB = turnB + 1

if(turnA > turnB):
  print('No')
else:
  print('Yes')

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    if(s[len-1]=='0' || s[len-1]=='1' || s[len-1]=='6' || s[len-1]=='8')
        cout<<"pon"<<endl;
    if(s[len-1]=='3')
        cout<<"bon"<<endl;
    if(s[len-1]=='2' || s[len-1]=='4' || s[len-1]=='5' || s[len-1]=='7' || s[len-1]=='9')
        cout<<"hon"<<endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

int main(){
  int n;
  scanf("%d", &n);
  double x[10];
  char s[10][4];
  for(int i=0; i<n; i++) scanf("%lf %s", &x[i], s[i]);
  
  double result = 0.0;
  for(int i=0; i<n; i++) {
    if(strcmp(s[i], "JPY") == 0){
      result += x[i];
    } else {
      result += x[i] * 380000.0;
    }
  }
  printf("%lf\n", result);
  
  
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var h int
	fmt.Scan(&h)
	total := 0
	count := 0
	if h == 1 {
		fmt.Println(1)
		return
	}
	for h >= 1 {
		total += int(math.Pow(2, float64(count)))
		if h%2 != 0 {
			h--
		}
		h /= 2
		count++
	}
	fmt.Println(total)
}


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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second

li n, arr[101], x, now, res;

int main () {
    cin >> n >> x;
    for (li i=0; i<n; i++) {
        cin >> arr[i];
    }
    now=0;
    res=1;
    li i=0;
    for (li i=1; i<=n && now<=x; i++) {
        now=now+arr[i-1];
        if (now<=x) res++;
    }
    cout << res;
}


Measured memory_bytes: 256
///created: 4/Jul/2019 18:18:11

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int modulo = 1e9 + 7;

#ifdef LOCAL_DEBUG_NTV1612
template<class __Ty>
string to_string(__Ty a) {
	string res = "[ ";
	bool f = true;
	for (auto &p : a) { res += (f ? string("") : string(", ")) + to_string(p); f = false;	}
	return res + " ]";
}
void _debug() { fprintf(stderr, "\n"); }
template<typename __Ty_head, typename... __Ty_tail>
void _debug(__Ty_head head, __Ty_tail... tail) { fprintf(stderr, "%s ", to_string(head).c_str()); _debug(tail...); }
#define debug(...) fprintf(stderr, "DEBUG [%s]: ", #__VA_ARGS__), _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

template<class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); }
template<class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); }
template<class __Ty> __Ty add(__Ty a, __Ty b) { return (a + b) % (__Ty(modulo)); }
template<class __Ty> __Ty sub(__Ty a, __Ty b) { __Ty m(modulo); return ((a - b) % m + m) % m; }

int a[505][505], h, w, sum = 0;
vector<ii> ans[2];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			cin >> a[i][j];
	vector<tuple<int, int, int, int> > ans;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j < w; ++j) {
			if (a[i][j] % 2 != 0) {
				a[i][j]--;
				a[i][j + 1]++;
				ans.push_back(make_tuple(i, j, i, j + 1));
			}
		}
		if (i < h && a[i][w] % 2 != 0) {
			a[i][w]--;
			a[i + 1][w]++;
			ans.push_back(make_tuple(i, w, i + 1, w));
		}
	}
	cout << ans.size() << '\n';
	for (int i = 0; i < int(ans.size()); ++i) {
		int x, y, u, v;
		tie(x, y, u, v) = ans[i];
		cout << x << ' ' << y << ' ' << u << ' ' << v << '\n';
	}
	return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; 
    while (cin >> s) {
        const int n = s.size(); 
        string a; a += s[0];
        int i = 1, ans = 1;
        while (i < n) {
            string b; b += s[i];
            if (a == b && i+1 < n)
                b += s[++i];
            if (a != b) {
                ans++; a = b; i++; 
            }
            else
                break;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 720
using System;

class MyClass
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        if (a < b && b < c)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


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

class Stack {
  int A[1000000];
  int top;

  public:
  Stack() { top = 0; }

  void push(int x) {
    A[++top] = x;
  }

  int pop() {
    return A[top--];
  }
};

int main() {
  int a, b;
  char ch[1000000];
  Stack stack;

  while( scanf("%s", ch) != EOF ) {
    if ( ch[0] == '+') {
      a = stack.pop();
      b = stack.pop();
      stack.push(a + b);
    } else if ( ch[0] == '-' ) {
      a = stack.pop();
      b = stack.pop();
      stack.push(b - a);
    } else if ( ch[0] == '*' ) {
      a = stack.pop();
      b = stack.pop();
      stack.push(a * b);
    } else {
      stack.push(atoi(ch));
    }
  }

  printf("%d\n", stack.pop());

  return 0;
}



Measured memory_bytes: 2712
A = [None, None, None]
B = [0, None, None]
C = [None, None, None]

for i in range(3):
	 A[i] = list(map(int,input().split())) 

flag = True

for i in range(3):
	for j in range(3):
		
		if B[i] == None:
			B[i] = A[i][j] - C[j]
		elif C[j] == None:
			C[j] = A[i][j] - B[i]
		elif A[i][j] != B[i] + C[j]:
			flag = False
		
if flag == True :
	print ("Yes")
else :
	print ("No")

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

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

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
#define SoArrt(a, n) sort(a, a + n);
#define SoArrtR(a, n) sort(a, a + n, std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n;

	cin >> n;

	int a[n];
	int ans = INT_MAX;
	int cost;

	int i, j;

	rep(i, n) cin >> a[i];

	SoArrt(a, n);

	repiin(i, a[n - 1], a[0]) {
		cost = 0;
		
		rep(j, n) cost += Abs(i - a[j]) * Abs(i - a[j]);

		Min(ans, cost);
	}

	Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int solve(int,int,int *,int);

int main()
{
  int i,n,A[21],q,m;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=1;i<=q;i++){
    scanf("%d",&m);
  if(solve(1,m,A,n))printf("yes\n");
  else printf("no\n");
  }
  return 0;
}

int solve(int i,int m,int A[],int n)
{
  int res;

  if(m == 0)return 1;
  if(i > n)return 0;

  res = solve(i + 1,m,A,n) || solve(i + 1,m - A[i],A,n);
  
  return res;
}

  



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 1)cout << "Odd" << endl;
	else cout << "Even" << endl;
}


Measured memory_bytes: 256
use proconio::input;
use std::vec::Vec;

fn find(x: isize, p: &[isize]) -> bool {
  for v in p.iter() {
    if *v == x {
      return true;
    }
  }
  false
}

fn main() {
  input! {
    x: isize,
    n: usize,
    mut p: [isize;n],
  }
  p.sort();
  let mut last = 0_isize;
  let mut diff = 10000_isize;
  for i in 0_isize..102_isize {
    if find(i, &p) {
      continue;
    }
    let d = (i - x).abs();
    if d >= diff {
      break;
    }
    diff = d;
    last = i;
  }
  println!("{}", last);
}


Measured memory_bytes: 2164
#include<iostream>
using namespace std;
int main() {
	int H, W;
	while (1) {
		
		cin >> H >> W;
		if (H==0&& W == 0) {
			break;
		}
		for (int i = 1; i <= H; i++) {
			for (int k = 1; k <= W; k++) {
				if ((i + k) % 2 == 0) {
					cout << '#';
				}
				else if ((i + k) % 2 != 0) {
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	int a , b ;
	cin >> a >> b ;
	b *= 2 ;
	cout << max(0,a-b) << endl;
}


Measured memory_bytes: 256
a , b , c , x , y = map(int,input().split())
n = max(x,y)
kar = a*x + b*y
for i in range(1,n+1):
    if kar > a*(max(0,x-i)) + b*(max(0,y-i)) +2*c*i:
        kar = a*(max(0,x-i)) + b*(max(0,y-i)) +2*c*i
print(kar)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	string s; cin >> s;
	string out;
	for (int i = 0; i < s.size(); i += 2) {
		out += s[i];

	}
	print(out);
	return 0;
}

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

int main()
{
  string s,t;
  cin>>s>>t;
  int ans=0;
  for(int i=0;i<s.length();i++)
    if(s[i]!=t[i])
      	ans++;
  cout<<ans;
  return 0;
}

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

int dig(int n) {
  if (n < 10) return 1;
  if (n < 100) return 2;
  if (n < 1000) return 3;
  if (n < 10000) return 4;
  if (n < 100000) return 5;
  return 6;
}

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

  int ans = 0;

  for (int i = 1; i <= N; i++) {
    if (dig(i) % 2 == 1) ans++;
  }

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

Measured memory_bytes: 256
S=input()
if S=='keyence' or S[0:7]=='keyence' or S[-7:]=='keyence':
    print('YES')
    exit()
else:
    pass

if S[0]=='k':
    if S[-6:]=='eyence':
        print('YES')
        exit()
    else:
        pass
if S[:2]=='ke':
    if S[-5:]=='yence':
        print('YES')
        exit()
    else:
        pass
if S[:3]=='key':
    if S[-4:]=='ence':
        print('YES')
        exit()
    else:
        pass
if S[:4]=='keye':
    if S[-3:]=='nce':
        print('YES')
        exit()
    else:
        pass
if S[:5]=='keyen':
    if S[-2:]=='ce':
        print('YES')
        exit()
    else:
        pass
if S[:6]=='keyenc':
    if S[-1]=='e':
        print('YES')
        exit()
    else:
        pass
print('NO')

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

int main() {
  int k,s;
  cin >> k >> s;

  int count = 0;
  int x,y;
  for(int x=0;x<=k;x++) {
    for(int y=0;y<=k;y++) {
      if(s-x-y >= 0 && s-x-y <= k) { //Z
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000

typedef struct queue
{
	int front;
	int rear;
	int data[200];
}queue;

void init(queue* p)
{
	p->front = 0;
	p->rear = 0;
}

void enqueue(queue *p,int x)
{
	if (next(p->rear) == p->front)
		printf("OVERFLOW!\n");
	p->data[p->rear] = x;
	p->rear = next(p->rear);
}

int dequeue(queue *p)
{
	int x;

	if (p->front == p->rear)
		printf("NO DADA\n");

	x = p->data[p->front];
	p->front = next(p->front);

	return x;
}

int empty(queue *p)
{
	return p->front == p->rear;
}

void print(char* str, int a, int b)
{
	int i;

	for (i = a; i <= b; i++)
		printf("%c", str[i]);
	printf("\n");
}

void reverse(char* str, int a, int b)
{
	int i,j=0;
	char t;

	for (i = a; i <= (a + b) / 2; i++)
	{
		t = str[i];
		str[i] = str[b - j];
		str[b - j] = t;
		j++;
	}
}

void replace(char* str, int a, int b, char* temp)
{
	int i, j=0;

	for (i = a; i <= b; i++)
	{
		str[i] = temp[j];
		j++;
	}
}

int main()
{
	double x1, y1, x2, y2;

	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);

	printf("%lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)));
	return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>

int main(void){

int a,b,c,n,x;

n=0;

x=0;

scanf("%d %d %d",&a,&b,&c);

if(a>=1&&a<=10000&&b>=1&&b<=10000&&c>=1&&c<=10000){

for(a;a<=b;a++){

if(c%a==0){

x=x+1;

}

}

}

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

return 0;

}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define rep(i,s,t) for (register int i=s;i<=t;i++)
#define drep(i,s,t) for (register int i=s;i>=t;i--)
#define N 100000
using namespace std;
int n,m,a[N+5],blo[N+5],L[N+5],R[N+5],s,bs,to[N+5],t[N+5],nex[N+5];
int query(int l,int r)
{
    int ans=0;
    while (blo[l]<blo[r])
        ans+=t[l],l=nex[l];
    while (l<r)
        ans++,l=to[l];
    return ans;
}
int main()
{
    scanf("%d",&n);
    bs=sqrt(n);
    rep(i,1,n)
    {
        scanf("%d",&a[i]);
        blo[i]=(i-1)/bs+1;
        if (!L[blo[i]])
            L[blo[i]]=i;
        R[blo[i]]=i;
    }
    scanf("%d",&s);
    rep(i,1,n)
    {
        if (upper_bound(a+1,a+n+1,a[i]+s)!=a+n+1)
            to[i]=(upper_bound(a+1,a+n+1,a[i]+s)-a-1);
        else
            to[i]=n;
    }
    drep(i,n,1)
    {
        if (to[i]>=R[blo[i]])
            t[i]=1,nex[i]=to[i];
        else
            if (blo[to[i]]==blo[i])
                t[i]=t[to[i]]+1,nex[i]=nex[to[i]];
            else
                t[i]=1,nex[i]=to[i];
    }
    scanf("%d",&m);
    int l,r;
    rep(i,1,m)
    {
        scanf("%d%d",&l,&r);
        if (l>r)
            swap(l,r);
        printf("%d\n",query(l,r));
    }
    return 0;
}

Measured memory_bytes: 2816
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k]+C[k][j])

c = [0]*10
for h in range(H):
    for w in range(W):
        if A[h][w] >= 0:
            c[A[h][w]] += 1

ans = 0
for i in range(10):
    ans += C[i][1]*c[i]

print(ans)

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

int H[100001],way[100001]={0};

int main(){
  long long int i,X,j;
  cin>>X;
  for(i=0;i<=1000;i++){
    for(j=0;j<=1000;j++){
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      i=-i;
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      j=-j;
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      i=-i;
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      j=-j;
      cerr<<i<<' '<<j<<endl;
    }
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

#define ll long long

int main()
{
    int a, b;
    cin >> a >> b;
    if((b-a)%2==0){
        printf("%d\n", (b-a)/2+a);
    }else{
        printf("IMPOSSIBLE\n");
    }
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> X(N);
	for (auto &x : X) {
		cin >> x;
	}
	vector<int> sortedX = X;
	sort(sortedX.begin(), sortedX.end());
	int a = sortedX[N / 2 - 1];
	int b = sortedX[N / 2];
	for (auto x : X) {
		if (x <= a) {
			cout << b << endl;
		}
		else {
			cout << a << endl;
		}
	}
}


Measured memory_bytes: 3712
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Mon Feb  4 14:48:56 2019
//
package main

import "fmt"

type pair struct {
	x, y int
}

var H, W int

func in(x, y int) bool {
	return 0 <= x && x < H && 0 <= y && y < W
}
func dfs(g []string, dists [][]int) {
	dists[0][0] = 0
	q := []pair{pair{0, 0}}

	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		for _, d := range []pair{pair{1, 0}, pair{-1, 0}, pair{0, 1}, pair{0, -1}} {
			x, y := p.x+d.x, p.y+d.y
			if in(x, y) && g[x][y] == '.' && dists[x][y] == -1 {
				dists[x][y] = dists[p.x][p.y] + 1
				q = append(q, pair{x, y})
			}
		}
	}
}

func main() {
	fmt.Scan(&H, &W)

	g := make([]string, H)
	blacks := 0
	for i := range g {
		fmt.Scan(&g[i])
		for j := range g[i] {
			if g[i][j] == '#' {
				blacks++
			}
		}
	}

	dists := make([][]int, H)
	for i := range dists {
		dists[i] = make([]int, W)
		for j := range dists[i] {
			dists[i][j] = -1
		}
	}

	dfs(g, dists)
	if dists[H-1][W-1] == -1 {
		fmt.Println(-1)
	} else {
		fmt.Println(H*W - dists[H-1][W-1] - 1 - blacks)
	}
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    string S;
    cin >> S;

    int N = S.size();

    int ret = 0;
    int cntA = 0;
    rep(i, N) {
        if (S[i] == 'A') {
            cntA++;
        } else if (i + 1 < N && S[i] == 'B' && S[i + 1] == 'C') {
            ret += cntA;
            i++;
        } else {
            cntA = 0;
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
int n,m;
  scanf("%d%d",&n,&m);
  for(int i=m/n;i>=1;i--)if(m%i==0){
  printf("%d\n",i);
    return 0;
  }
}

Measured memory_bytes: 128
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	long[long[]] set;
	foreach (i; 0..N)
	{
		auto S = RD!string;
		long[] arr;
		foreach (c; S)
		{
			arr ~= c-'a';
		}
		++set[arr.idup];
	}

	long cnt;
	foreach (key; set.keys)
	{
		cnt.chmax(set[key]);
	}

	long[][] ans;
	foreach (key; set.keys)
	{
		if (set[key] == cnt)
		{
			ans ~= key.dup;
		}
	}

	ans.sort();

	foreach (e; ans)
	{
		string s;
		foreach (ee; e)
		{
			s ~= cast(char)(ee+'a');
		}
		writeln(s);
	}
	stdout.flush;
	debug readln;
}

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

int main() {
	ll n, z, w;
	cin >> n >> z >> w;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	if (n == 1) {
		cout << abs(a[0] - w) << endl;
		return 0;
	}
	ll ans = max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2]));
	cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	vll a(n);
	ll sum=0;

	rep(i, n){
		cin >> a[i];
		sum += a[i];
	}

	vector<vll> dp(301, vll(90001));
	vector<vll> dp2(301, vll(90001));

	rep(i, n+1){
		rep(j, sum+1){
			if (i == 0){
				if (j == 0)
					dp[i][j] = 1;
				else
					dp[i][j] = 0;
			}else{
				dp[i][j] = 2*dp[i-1][j];
				if (j-a[i-1] >= 0) dp[i][j] += dp[i-1][j-a[i-1]];
				dp[i][j] %= 998244353;
			}
		}
	}

	rep(i, n+1){
		rep(j, sum+1){
			if (i == 0){
				if (j == 0)
					dp2[i][j] = 1;
				else
					dp2[i][j] = 0;
			}else{
				dp2[i][j] = dp2[i-1][j];
				if (j-a[i-1] >= 0) dp2[i][j] += dp2[i-1][j-a[i-1]];
				dp2[i][j] %= 998244353;
			}
		}
	}

	ll ans=0;

	for(ll i=(sum+1)/2; i<=sum; i++){
		ans += dp[n][i];
	}

	if (sum%2 == 0) ans -= dp2[n][sum/2];

	ll temp=1;
	rep(i, n){
		temp *= 3;
		temp %= 998244353;
	}

	ans = (temp - (ans*3) % 998244353) % 998244353;

	if (ans < 0) ans = 998244353 + ans;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 424512
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;

    int n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    map<int, int>mpp;
    map<int, int>:: iterator it;
    ll a[3][3];
    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            cin>>a[i][j];
        }
    }


    cin>>n;
    for(i=0; i<n; i++){
        cin>>x;
        mpp[x]++;
    }
    for(i=0; i<3; i++){
        x=0;
        for(j=0; j<3; j++){
            if(mpp[a[i][j]]!=0){
                x++;
            }
        }
        if(x==3)f=1;
    }
    for(i=0; i<3; i++){
        x=0;
        for(j=0; j<3; j++){
            if(mpp[a[j][i]]!=0){
                x++;
            }
        }
        if(x==3)f=1;
    }
    if(mpp[a[0][0]]>0 && mpp[a[1][1]]>0 && mpp[a[2][2]]>0)f=1;
    if(mpp[a[2][0]]>0 && mpp[a[1][1]]>0 && mpp[a[0][2]]>0)f=1;

    if(f==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
#define N 500000
void merge(int A[],int left,int right);
int count=0;

int main(){ 
    int i,n,S[N];
scanf("%d",&n);    
for(i=0;i<n;i++) scanf("%d",&S[i]);
merge(S,0,n-1);

for(i=0;i<n-1;i++)
printf("%d ",S[i]);
printf("%d",S[n-1]);
printf("\n%d\n",count);

return 0;
}

void merge(int A[],int left,int right){
int i,j,k,L[N],mid;
  //n1 = mid - left;
  //n2 = right - mid;
//  L[0...n1], R[0...n2] を生成
if(left<right){
    mid=(left+right)/2;
    merge(A, left, mid); 
    merge(A, mid+1, right); 
  for(i=mid;i>=left;i--){
    L[i] = A[i];
    count++;
  }
  for(j=mid+1;j<=right;j++){
    L[right-(j-(mid+1))] = A[j];
    count++;
  }
i=left;
j=right;
for(k=left;k<=right;k++){
    if(L[i]<L[j]) {
      A[k]=L[i++]; 
    }
    else {
      A[k]=L[j--]; 
    }
}
}
}


Measured memory_bytes: 40844
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll N;
ll n[2][3];
ll dp[25000001];

int main(){
    cin>>N;
    rep(i,2) rep(j,3) cin>>n[i][j];
    dp[N]=N;
    ll ans=0;
    rep(i,3) if(n[0][i]<n[1][i]){
        for(int j=N; j>=n[0][i] ; j--) dp[j-n[0][i]]=max(dp[j-n[0][i]],dp[j]+n[1][i]-n[0][i]);
    }
    rep(i,N+1) ans=max(ans,dp[i]);
    rep(i,N+1) dp[i]=0;
    dp[ans]=ans;
    rep(i,3) if(n[0][i]>n[1][i]){
        for(int j=ans; j>=n[1][i];j--) dp[j-n[1][i]]=max(dp[j-n[1][i]],dp[j]+n[0][i]-n[1][i]);
    }

    ll X=ans;
    rep(i,X+1) ans=max(ans,dp[i]);
    cout<<ans<<endl;


    
}

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

int dfs(int u, vector<vector<int> > &g, vector<int> &vis)
{
    vis[u] = 1;
    int ans = 1;

    for (int v : g[u])
        if (!vis[v])
            ans += dfs(v, g, vis);

    return ans;
}

void solve()
{
    int N, E;
    cin >> N >> E;

    vector<vector<int> > adj(N + 1);
    set<pair<int, int> > edges;

    for (int i = 0; i < E; i++)
    {
        int u, v;
        cin >> u >> v;

        if (edges.find({min(u, v), max(u, v)}) != edges.end())
            continue;

        adj[u - 1].push_back(v - 1);
        adj[v - 1].push_back(u - 1);
    }

    int ans = 0;
    vector<int> visited(N + 1, 0);

    for (int i = 0; i < N; i++)
        if (!visited[i])
            ans = max(ans, dfs(i, adj, visited));

    cout << ans << endl;
}

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

Measured memory_bytes: 24256
import heapq

n, m, s, t = map(int, input().split())

Yen_cost = dict([[i, []] for i in range(n)])
Snuuk_cost = dict([[i, []] for i in range(n)])
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    Yen_cost[u].append((v, a))
    Yen_cost[v].append((u, a))
    Snuuk_cost[u].append((v, b))
    Snuuk_cost[v].append((u, b))

def Digkstra(Cost_dict, start):   
    dist = [float('inf') for _ in range(n)]
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while len(q) != 0:
        prov_cost, src = heapq.heappop(q)

        if dist[src] < prov_cost:
            continue

        for dest, cost in Cost_dict[src]:
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost
                heapq.heappush(q, (dist[dest], dest))
    return dist

Yen_dist = Digkstra(Yen_cost, s-1)
Snuuk_dist = Digkstra(Snuuk_cost, t-1)

First = 10**15
Money = []
Money.append(int(First - Yen_dist[-1] - Snuuk_dist[-1]))
for year in range(n-2, -1, -1):
    temp = First - Yen_dist[year] - Snuuk_dist[year]
    if temp > Money[-1]:
        Money.append(temp)
    else:
        Money.append(Money[-1])

for i in range(n):
    print(Money[-1-i])


Measured memory_bytes: 97004
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;cin>>s;
    cout<<s.substr(0,3)<<nnn;
    return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedInputStream;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    static final int MAX = 1_000_000_000;
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n= sc.nextInt();
        int k = sc.nextInt();
        //sc.nextLine();
        System.out.println(6-(n+k));
    }
    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }
    private static int[] toArray(String text) {
        return Arrays.stream(text.split("")).mapToInt(Integer::valueOf).toArray();
    }

}

Measured memory_bytes: 20692
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        long A = nextLong();
        long B = nextLong();
        long N = nextLong();

        double x = Math.min(N, B);
        if(N >= B){
            x -=1;
        }
        println((int)Math.floor((A*x/B)));
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 35668
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # j - i ≠ k - j という式から、 j - i = k - j を満たす奴を減らせばいーのよ

    n = int(input())
    S = input()
    cnt = S.count('R')*S.count('G')*S.count('B') # 全通り
    # N が 4000 O(n^2)なら間に合うか！
    # k = 2j - i という式？　短縮できそう？
    for i in range(n):
        for j in range(i+1,n):# 同じところを参照しても意味ないので、iの次から調べてみる
            if S[i] == S[j]:# まずiとj(隣り合うもの)が一緒はだめ
                continue
            k = 2*j - i # = を満たしてしまうものをひく
            if k >= n or S[k] == S[i] or S[k] == S[j]: # n 以上(ありえない)の場合
            # それと、記号が一致はしてないよね？ って時は、数え上げてすらないからだめ
            # continueする
                continue
            cnt -= 1
    print(cnt)


if __name__ == '__main__':
  main()


Measured memory_bytes: 9108