akhauriyash/Code-Regression huggingface dataset:
//2017-10-12
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (100000+5)

int a[N];

int main(){
	int n, dif = 0;
	scanf("%d", &n);

	For(i, 1, n) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	For(i, 1, n) if(a[i] != a[i-1]) ++dif;

	int cnt = 0, l = 1, r = n;
	while(dif > 1 || (a[l] > cnt+1 && dif && l<r)){
		++cnt;
		while(l <= r && a[l] == cnt){
			if(a[l] != a[l+1]) --dif; ++l;
		}

		if(a[r] != a[r-1]) --dif;
		--r;
	}

	if(!dif){
		++r; --l;
		while(l && a[l-1] == cnt) --l;
		--cnt;
	}

	int t1 = (r-l+1) & 1, t2 = (a[r]-cnt) & 1;
	if(t1 && t2) puts("Second");
	else puts("First");

	return 0;
}

Measured memory_bytes: 640
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int i;
  int v;

  Node(int i = -1, int v = -1) {
    this->i = i;
    this->v = v;
  }

  bool operator>(const Node &n) const {
    return v < n.v;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> A;
  priority_queue <Node, vector<Node>, greater<Node> > pque;
  priority_queue <int, vector<int>, greater<int> > ids;

  ll sum = 0;
  int a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    sum += a;
    pque.push(Node(i, a));
  }

  ll ans[N];
  memset(ans, 0, sizeof(ans));
  vector<Node> checked;

  while (!pque.empty()) {
    Node cand = pque.top();
    ids.push(cand.i);
    checked.push_back(cand);
    pque.pop();

    while (!pque.empty() && pque.top().v == cand.v) {
      Node node = pque.top();
      pque.pop();
      checked.push_back(node);
      ids.push(node.i);
    }

    int id = ids.top();
    // fprintf(stderr, "id = %d\n", id);

    if (pque.empty()) {
      ans[id] += sum;
    } else {
      int diff = cand.v - pque.top().v;
      ll cnt = diff * ids.size();
      ans[id] += cnt;
      sum -= cnt;
    }
  }

  for (int i = 0; i < N; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4852
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn keta_sum(mut v:i32) -> i32 {
    let mut n:i32 = 0;
    while v != 0 {
        n += v % 10;
        v /= 10;
    }
    n
}

fn main() {
    let n:i32 = read();
    let a:i32 = read();
    let b:i32 = read();
    let sum:i32 = (1..n+1).filter(|i| {
        let k:i32 = keta_sum(*i);
        a <= k && k <= b
    }).sum();
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int e,Pri[N>>1],n,f;
long long a[N],w[N],c[N];
bool pri[N],flag;
map <long long,int> cot;
map <long long,bool> jug;
void P(){
    pri[0]=pri[1]=1;
    for(long long i=2;i<=1e5;i++){
        if(!pri[i]){
            pri[i]=1;
            Pri[++e]=i;
            jug[i*i]=1;
        }
        for(int j=1;j<=e&&i*Pri[j]<=1e5;j++){
            pri[i*Pri[j]]=1;
            if(!(i%Pri[j])) break;
        }
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    P();
    for(int i=1;i<=n;i++){
        w[i]=1;
        long long W=1,sto=1;
        for(int j=1;Pri[j]<=a[i]&&j<=2400;j++){
            long long v=Pri[j],tal=0;
            while(!(a[i]%v)) a[i]/=v,tal++;
            tal%=3;
            if(tal){
            	for(int _=1;_<=tal;_++) sto*=Pri[j];
            	for(int _=1;_<=3-tal;_++) W*=Pri[j];
            }
        }
		sto*=a[i];
        if(a[i]){
        	if(jug[a[i]]) W*=sqrt(a[i]);
        	else W*=a[i]*a[i];
        }
        if(sto==1) flag=1;
        if(!cot[sto]&&sto!=1){
            c[++f]=sto;
            w[f]=W;
        }
        cot[sto]++;
    }
    long long ans=0;
    for(int i=1;i<=f;i++) if(cot[c[i]]){
        ans+=max(cot[c[i]],cot[w[i]]);
        cot[c[i]]=cot[w[i]]=0;
    }
    if(flag) ans++;
    cout<<ans<<endl;
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int passed_num = 0;
    int inter = 0;
    vector<string> ans;
    rep(i, s.size()) {
        if (s[i] == 'a' and passed_num < a + b) {
            passed_num++;
            ans.emplace_back("Yes");
        } else if (s[i] == 'b') {
            inter++;
            if (passed_num < a + b and inter <= b) {
                passed_num++;
                ans.emplace_back("Yes");
            } else
                ans.emplace_back("No");
        } else
            ans.emplace_back("No");
    }

    rep(i, n)
        out(ans[i]);

    return 0;
}


Measured memory_bytes: 6212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var A = GetIntArray();
            var D = A.Distinct();

            var ans = A.Count() == D.Count() ? "YES" : "NO";
            Console.WriteLine(ans);
        }




        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 38728
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  map<string, int> mp;
  string str;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    mp[str]++;
  }
  cout << "AC" << " x " << mp["AC"] << endl;
  cout << "WA" << " x " << mp["WA"] << endl;
  cout << "TLE" << " x " << mp["TLE"] << endl;
  cout << "RE" << " x " << mp["RE"] << endl;

  return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <string.h>

#define MAXTURN 1000
#define MAXLENGTH 100

typedef struct{
	char card[MAXTURN][MAXLENGTH];
	int point;
}Game;

int main(void)
{
	int i, result, turn;
	Game taro;
	Game hanako;

	scanf("%d", &turn);
	for(i = 0; i < turn; i++){
		scanf("%s %s", taro.card[i], hanako.card[i]);
	}

	taro.point = 0;
	hanako.point = 0;
	for(i = 0; i < turn; i++){
		result = strcmp(taro.card[i], hanako.card[i]);
		if(result >= 1){
			taro.point += 3;
		}
		else if(result == 0){
			taro.point += 1;
			hanako.point += 1;
		}
		else{
			hanako.point += 3;
		}
	}

	printf("%d %d\n", taro.point, hanako.point);
	
	return 0;
}


Measured memory_bytes: 2108
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long dfs(in long[] p, long[] arr, int bits, int depth)
{
  if (depth == 4) {
    return min(arr[0], arr[1]) * min(arr[2], arr[3]);
  }
  long ans = 0;
  foreach (i; 0..4) {
    if ((bits >> i) & 1) {
      continue;
    }
    arr[depth] = p[i];
    ans = max(ans, dfs(p, arr, bits | 1 << i, depth + 1));
  }
  return ans;
}

void main()
{
  int n = readln.chomp.to!int;
  long[] a = readln.chomp.split.map!(to!long).array;
  int[long] cnt;
  foreach (v; a) {
    cnt[v]++;
  }
  a = std.algorithm.sort(a).uniq.retro.array;
  long ans = 1;
  bool done = false;
  foreach (v; a) {
    if (cnt[v] < 2) {
      continue;
    }
    if (done) {
      ans *= v;
      ans.writeln;
      return;
    }
    if (cnt[v] >= 4) {
      ans *= v * v;
      ans.writeln;
      return;
    }
    ans *= v;
    done |= true;
  }
  0.writeln;
}


Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int a[n+5];
    for(int i=1;i<=n;i++)
        {cin>>a[i];
        if(i%2==1&&a[i]%2==1)
            cnt++;}
        cout<<cnt;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll k,num;
void bfs(){
    queue<ll> q;
    for(int i=1;i<=9;i++){
        q.push(i);
    }
    while(!q.empty()){
        ll sz=q.size();
        for(int l=1;l<=sz;l++){
            ll x=q.front();
            q.pop();num++;
            if(num==k){
                cout<<x<<endl;
                exit(0);
            }
            for(ll i=0;i<=9;i++){
                if(abs(x%10-i)<=1) q.push(x*10+i);
            }
        }
    }
}
int main(){
    cin>>k;
    bfs();
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int rui[100002];
int main(){
    int N,M;
    cin>>N>>M;
    long long int bef;
    for(int i=0;i<M;i++){
        long long int a;
        cin>>a;
        if(i!=0){
            rui[min(a,bef)]++;
            rui[max(a,bef)]--;
        }
        bef=a;
    }
    for(int i=1;i<100002;i++)rui[i]+=rui[i-1];
    long long int ans=0;
    for(int i=1;i<N;i++){
        long long int a,b,c;
        cin>>a>>b>>c;
        ans+=min(rui[i]*a,c+rui[i]*b);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1948
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

void radix_sort(vector<int>::iterator b,vector<int>::iterator e) {
    vector<int> t(e - b);
    array<int, 256> c, s;
    for (int i = 0; i < 32; i += 8) {
        fill(c.begin(), c.end(), 0);
        for_each(b, e, [&](int j) {c[(j >> i) & 255]++;});
        s[0] = 0;
        partial_sum(c.begin(), c.end() - 1, s.begin() + 1);
        for_each(b, e, [&](int j) {t[s[(j >> i) & 255]++] = j;});
        copy(t.begin(), t.end(), b);
    }
}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		sort(t.begin(), t.end());
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		radix_sort(u.begin(), u.end());
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			r = max(r, *i + *e);
		}
		outl(r);
	}
}


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

int main(){
    long long int n,x, ans=0,dai=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        dai=max(x,dai);
        if(x<=dai)ans+=dai-x;
        }
    cout<<ans<<endl;
    return 0;
}


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
vector<int>v[100000];
vector<int>ans;
int visited[100000];
void add(deque<int>&dq)
{
    int x=dq.front();
    for(auto c:v[x])
    {
        if(!visited[c])
        {
            visited[c]=1;
            dq.push_front(c);
            add(dq);
            return ;
        }
    }
    int y=dq.back();
    for(auto c:v[y])
    {
        if(!visited[c])
        {
            visited[c]=1;
            dq.push_back(c);
            add(dq);
            return ;
        }
    }
}
int32_t main() {
    nitin;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    deque<int>dq;
    visited[0]=1;
    dq.push_back(0);
    add(dq);
    cout<<dq.size()<<endl;
    while(!dq.empty())
    {
        cout<<dq.front()+1<<" ";
        dq.pop_front();
    }
    return 0;
}

Measured memory_bytes: 10576
/*
    Author      : Dinesh Verra
    College     : ABV-IIITM
    Date        : 14/08/2020
*/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
using namespace std;
typedef long long ll;
// #define ll int
typedef unsigned long long ull;
#define cu continue
#define br break
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define inf 1000000000000
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define vpll vector <pll>
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define all(v) v.begin(),v.end()
#define nl cout<<'\n'

template <typename A1>
void prn(A1&& arg)
{
	cout<<arg<<'\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args)
{
	cout<<arg<<' ';
	prn(args...);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,d;
	cin>>n>>k>>d;
	n=abs(n);
	ll x=n/d;
	if(x>k)
	{
		n-=(k*d);
		prn(abs(n));
	}
	else
	{
		n%=d;
		k-=x;
		if(k&1) n-=d;
		prn(abs(n));
	}
}

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

int main() {
	int A,B;
	cin >> A >> B;
	if((A+B)%2 == 1) cout << "IMPOSSIBLE";
	else cout << (A+B)/2;
}


Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		sc.close();
		char[] C = S.toCharArray();

		int ans = 0;

		for(int i=0;i<S.length();i++) {
			if(C[i]!=C[S.length()-1-i]) {
				ans ++;
			}
		}
		System.out.println(ans/2);
	}
}

Measured memory_bytes: 23124
S = list(input())

cnt_g = 0
cnt_p = 0
ans = 0

for s in S:
    if cnt_p < cnt_g:
        if s == "g":
            cnt_p += 1
            ans += 1
        else:
            cnt_p += 1
    else:
        if s == "g":
            cnt_g += 1
        else:
            cnt_g += 1
            ans -= 1

print(ans)

Measured memory_bytes: 3956
fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map { it.toInt() }
    // (pref, year)
    val cities = mutableListOf<Pair<Int, Int>>()
    // (pref, years)
    val map = mutableMapOf<Int, MutableList<Int>>()
    
    for (i in 1..m) {
        val (p, y) = readInputLine().split(" ").map { it.toInt() }
        cities.add(Pair(p, y))
        
        val prefInfo = map.get(p) ?: mutableListOf<Int>()
        prefInfo.add(y)
        map.put(p, prefInfo)
    }
    
    // 各県の年数をソート
    map.forEach { it.value.sort() }
    
    for (city in cities) {
        val prefInfo = map.get(city.first)!!
        println(city.first.toString().padStart(6, '0') + (prefInfo.binarySearch(city.second) + 1).toString().padStart(6, '0'))
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 103084
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        ll N; cin >> N;
        if (N==0) break;
        vector<ll> A(N);
        rep(i,N) cin >> A[i];

        ll ave = accumulate(all(A),0LL) / N;
        int ans = 0;
        rep(i,N) {
            if (A[i] <= ave) ans++;
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3248
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
long long a[105];
int main()
{
	long long n,maxi=0,mini=99999999999,ans;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		maxi=max(a[i],maxi),mini=min(a[i],mini);
	ans=maxi-mini;
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int mod=1000000007;


long long int n,k,pownum,q,a[60]={},id,res=0,memo,key=0,mypow[66]={1};
queue<pair<long long ,long long > >que;
int main() {
    const long long int INF=99999999999999;
	map<long long int, long long int>mp;
    string str[550],red[550],blue[550];
    priority_queue<long long int>pq[4];
    priority_queue<long long int>tmp[4];
	cout << fixed << setprecision(10);
    cin>>n;
    for(long long int i=1;mypow[i-1]<10000000000001000;i++){
        mypow[i]=mypow[i-1]*n;
        pownum=i;
    }
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    while(1){
        key=1;
        for(int i=1;i<=n;i++){
            
            if(a[i]/n!=0){
                id=i;
                res+=a[i]/n;
                key=0;
                memo=a[i]/n;
                for(int j=1;j<=n;j++){
                    if(id==j){
                        a[j]=a[id]%n;
                    }else{
                        a[j]+=memo;
                    }
                    //cout<<a[j]<<" ";
                }
                //cout<<endl;
            }
        }
        if(key==1){break;}
    }
    cout<<res;
} 


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

long long fabs (long long n) {
    if (n < 0) return -n;
    else return n;
}

int main() {
    int n;
    cin >> n;
    vector<long long> sum(n+1);
    for (int i=0; i<n; i++) {
        long long num;
        cin >> num;
        sum[i+1] = sum[i] + num;
    }
    long long ans = 10101010101;
    for (int i=1; i<n; i++) {
        long long dist = (sum[n]-sum[i]) -sum[i];
        ans = min(ans, abs(dist));
    }
    cout << ans << endl;
}

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

int main(){
	int i, j;
	int a[100];
	string s;
	cin>>s;
	int len=s.size();
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<"-1"<<endl;
		return 0;
	}
	else if(len!=26){
		char ans;
		bool flag=false;
		string c("abcdefghijklmnopqrstuvwxyz");
		for(j=0; j<26; j++){
			flag=false;
			for(i=0; i<len; i++){
				if(c[j]==s[i]) flag=true;
			}
			if(!flag){
				ans=c[j];
				break;
			}
		}
		for(i=0; i<len; i++) cout<<s[i];
		cout<<ans<<endl;
		return 0;
	}
	else{
		int num;
		for(i=25; i>=1; i--){
			if(s[i-1]<s[i]){
				num=i;
				break;
			}
		}
		string t=s.substr(num);
		sort(t.begin(), t.end());
		char ans;
		int tlen=t.size();
		for(i=0; i<tlen; i++){
			if(t[i]>s[num-1]){
				ans=t[i];
				break;
			}
		}
		for(i=0; i<num-1; i++) cout<<s[i];
		cout<<ans<<endl;
		return 0;
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong H, N;
  vector<lpair> AB;

  cin >> H >> N;
  AB.resize(N);
  for (auto &in: AB) {
    cin >> in.first >> in.second;
  }

  vector<llong> dp(H + 1, inf<llong>);
  for (auto &ab: AB) {
    for (int i = 0; i <= H; ++i) {
      if (i <= ab.first) {
        dp[i] = min(dp[i], ab.second);
      }
      else {
        dp[i] = min(dp[i], dp[i - ab.first] + ab.second);
      }
    }
  }

  cout << dp[H] << endl;

  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define N 110000
using namespace std;
int n,m,f[N],flag[N],pr[N],sz[N],p,c,d,u,v,df[N];
vector<int>a[N];
int get(int x){
	if(f[x]==x) return x;
	return f[x]=get(f[x]);
}
bool dfs(int u,int fa){
	if(flag[u] and pr[u]!=pr[fa]^1) return false;
	if(flag[u]) return true;
	pr[u]=pr[fa]^1;
	flag[u]=1;
	for(int i=0;i<a[u].size();++i)
		if(a[u][i]!=fa) if(!dfs(a[u][i],u)) return false;
	return true;
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) f[i]=i;
	for(int i=1;i<=m;++i){
		scanf("%d%d",&u,&v);
		a[u].push_back(v),a[v].push_back(u);
		int xx=get(u),yy=get(v);
		if(xx!=yy) f[xx]=yy;
	}
	for(int i=1;i<=n;++i)
		if(get(i)==i) df[i]=dfs(i,0);
	for(int i=1;i<=n;++i) sz[get(i)]++;
	for(int i=1;i<=n;++i){
		if(get(i)==i)
			if(sz[i]==1) p++;
			else if(df[i]) c++;
			else d++;
		}
	printf("%lld\n",1ll*p*n+1ll*(n-p)*p+1ll*c*c*2+1ll*d*(d+c*2));
	return 0;
}

Measured memory_bytes: 9088
import sys


def input():
    return sys.stdin.readline().rstrip()



def main():
    N = int(input())

    dp = [0] * (N + 1)
    rt = int(N ** 0.5) + 1
    for i in range(1, rt):
        ii = i ** 2
        for j in range(1, rt):
            iji = ii + j **2 + i * j

            if iji + 1 + i + j > N:
                break
            for k in range(1, rt):
                case = iji + k**2 + i * k + j * k
                if case <= N:
                    dp[case] += 1
                else:
                    break

    print(*dp[1:N + 1], sep="\n")


if __name__ == "__main__":
    main()


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

int main() {
    int N, M;
    string str;

    string tmp = "CODEFESTIVAL2016";

    cin >> str;

    int count = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] != tmp[i]) count++;
    }

    cout << count << endl;

    return 0;
}


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

int main()
{
    int A,B;
    cin>>A>>B;
    if(A>=13)
    {
        cout<<B<<endl;
    }
    else if(A<=12 && A>=6)
    {
        cout<<B/2<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}


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

class Ans
{
public:
	int p,t,l;
	Ans(int p, int t, int l)
		:p(p),t(t),l(l)
	{}

	bool operator<(const Ans& ans) const
	{
		return t>ans.t;
	}
};

int M,N,D[100];
int ssend, srecv;
int psend[100], precv[100];

void calc(priority_queue<Ans>& q)
{
	int tt=1,ansn=0,ansl=0,alansn=0, alansl=0;
	bool ansed[100]={0},nwansed[100]={0};
	int lg[100]={0};
	
	q.push(Ans(0,99999,0));

	while(1)
	{
		Ans a=q.top(); 
		if(tt > 20) break;
		
		if(a.t < tt*1000) 
		{
			ansed[a.p]=1;
			nwansed[a.p]=1;
			
			ansn++;
			ansl+=a.l;
			alansn++;
			alansl+=a.l;
			
			lg[a.p]=a.l;
			
			q.pop();
		}
		else
		{
			++tt;
			if(ansn==0) continue;
			
			for(int i=0; i<M; i++)
			{
				if(nwansed[i])
				{
					if(alansn>1)
					{
						ssend+=4+2*(alansn-1)+(alansl-lg[i]);
						precv[i]+=4+2*(alansn-1)+(alansl-lg[i]);
					}
				}
				else if(ansed[i])
				{
					ssend+=4+2*ansn+ansl;
					precv[i]+=4+2*ansn+ansl;
				}
				else
				{
					ssend+=4+ansn;
					precv[i]+=4+ansn;
				}
				
			}
			
			ansn=0;
			ansl=0;
			memset(lg,0,sizeof(lg));
			memset(nwansed, 0, sizeof(nwansed));
		}
	}
}

int main()
{
	bool b=0;
	while(cin >> M >> N, (M||N))
	{
		if(b) cout << endl;
		b=1;
		
		for(int i=0; i<M; i++)
			cin >> D[i];

		ssend=0;
		srecv=0;
		memset(psend,0,sizeof(psend));
		memset(precv,0,sizeof(precv));

		for(int i=0; i<N; i++)
		{
			ssend+=3*M;
			for(int j=0; j<M; j++)
				precv[j]+=3;
			
			int L;
			cin >> L;
			priority_queue<Ans> q;
			for(int j=0; j<L; j++)
			{
				int P,T;
				string A;
				cin >> P >> T >> A;
				q.push(Ans(P,T+D[P]*2,A.size()));

				psend[P]+=5+A.size();
				srecv+=5+A.size();
			}

			calc(q);
			ssend+=4*M;
			for(int j=0; j<M; j++)
				precv[j]+=4;
			
		}

		cout << ssend << " " << srecv << endl;
		for(int i=0; i<M; i++)
			cout << psend[i] << " " << precv[i] << endl;
	}
}

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

main(){
  int a=0,b=0;
  cin >> a >> b;

  if(a < b)
    cout << "a < b" << endl;

  if(a > b)
    cout << "a > b" << endl;

  if(a==b)
    cout << "a == b" << endl;
  else return 0;
}

Measured memory_bytes: 1156
#include <iostream>
using namespace std;
int main(void){
  int n,d;
  cin >> n >> d;
  int siya = 1 + 2*d;
  if(siya >= n){
  cout << 1 << endl;
  }
  else{
    if(n%siya == 0){cout << n/siya << endl;}
    else{cout << n/siya + 1 << endl;}
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
#define printv(v) for(auto it : v) cout<<it<<" ";cout<<endl;
#define prec(n) fixed<<setprecision(n)
const lli mod = 1000000007;
const int mod2 = 998244353;
const int N = 1e5;

lli binomialCoeff(int n, int k) 
{ 
    lli C[k+1]; 
    memset(C, 0LL, sizeof(C)); 
  
    C[0] = 1LL;  // nC0 is 1 
  
    for (int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = (lli)(C[j] + C[j-1])%mod; 
    } 
    return C[k]%mod; 
} 

int main()
{
	optimize

	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
	#endif

	int s;
	cin>>s;
	int m = s/3;

	lli ans = 0LL;

	forab(i,1,m+1)
	{
		ans = (ans+binomialCoeff(s-2*i-1, i-1))%mod;
	}

	cout<<ans<<endl;


	

	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int n;
int t[105000];
int x[105000];
int y[105000];

int main(){
	cin >> n;
	t[0] = 0; x[0] = 0; y[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	int dt, dx, dy;
	for (int i = 1; i <= n; i++) {
		dt = t[i] - t[i - 1];
		dx = abs(x[i] - x[i - 1]);
		dy = abs(y[i] - y[i - 1]);

		if (dx + dy > dt) {
			cout << "No" << endl;
			return 0;
		}
		else if ((dt - dx + dy) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
	
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
int mul(int *A,int *B)
{
    if((*A>=1&&*A<=9)&&(*B>=1&&*B<=9))
    return (*A)*(*B);
    else
    return -1;
}
int main()
{
   int A=0,B=0;
   scanf("%d %d",&A,&B);
   int res=mul(&A,&B);
   printf("\n%d",res);
   return 0;
}
  

Measured memory_bytes: 128
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{ //Perform BFS from 2...N then use those values to print

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		String S = input.next();
		if (S.length()<=x) System.out.println(S);
		else System.out.println(S.substring(0,x)+"...");
	}	
}

Measured memory_bytes: 27064
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "stack"
#include "functional"

using namespace std;
using ll = long long int;
using PII = pair<ll, ll>;

#define FOR(i, b, n) for(ll (i)=(a); (i)<(n); ++(i))
#define REP(i, n) FOR(a, 0, n)

struct rollingHash {
	ll mo[2] = { 1000000009, 998244353 };
	ll base[2] = { 1009, 1007 };
	vector<ll> hash[2], power[2];

	rollingHash() {}
	rollingHash(string s) {
		hash[0].resize(s.size() + 1); hash[1].resize(s.size() + 1);
		power[0].resize(s.size() + 1); power[1].resize(s.size() + 1);
		init(s);
	}

	inline ll mul(ll a, ll b, ll md) const {
		return a * b % md;
	}

	void init(string s) {
		for (int i = 0; i < 2; ++i) {
			power[i][0] = 1;
			for (int j = 1; j < s.size(); ++j) power[i][j] = mul(power[i][j - 1], base[i], mo[i]);
		}
		for (int i = 0; i < 2; ++i) for (int j = 0; j < s.size(); ++j) {
			hash[i][j + 1] = (hash[i][j] + mul(power[i][j], s[j] - 'A' + 1, mo[i])) % mo[i];
		}
	}

	bool equal(int l1, int r1, int l2, int r2) {
		for (ll i = 0; i < 2; ++i) {
			ll a = (hash[i][r1] - hash[i][l1] + mo[i]) % mo[i];
			ll b = (hash[i][r2] - hash[i][l2] + mo[i]) % mo[i];
			if (mul(a, power[i][l2 - l1], mo[i]) != b) return false;
		}
		return true;
	}
};

vector<ll> Zalgo(string s) {
	vector<ll> v(s.size());
	v[0] = s.size();
	int i = 1, j = 0;
	while (i < s.size()) {
		while (i + j < s.size() && s[j] == s[i + j]) ++j;
		v[i] = j;
		if (j == 0) { ++i; continue; }
		int k = 1;
		while (i + k < s.size() && k + v[k] < j) v[i + k] = v[k], ++k;
		i += k, j -= k;
	}
	return v;
}

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

	string s;
	cin >> s;

	const ll INF = 1LL << 30;
	ll ans = INF;
	// rollingHash hash(s);
	auto v = Zalgo(s);
	for (ll i = 1; i <= s.size(); ++i) {
		ll len = (ll)s.size() - i * 3;
		if (len <= 0 || len % 2) continue;
		len /= 2;
		ll idx1 = i - 1, idx2 = i + len - 1, idx3 = 2 * i + len - 1, idx4 = 2 * i + 2 * len - 1;
		if (v[i + len] == 2*i + len && v[2 * i + 2 * len] == i) {
			ans = min(ans, i + len);
		}
		//if (hash.equal(0, idx1, idx2 + 1, idx3) && hash.equal(idx2 + 1, idx3, idx4 + 1, s.size() - 1) && hash.equal(idx1 + 1, idx2, idx3 + 1, idx4)) {
		//	if (ans > i + len) {
		//		ans = i + len;
		//	}
		//}
	}

	if (ans == INF) cout << "mitomerarenaiWA" << endl;
	else cout << "Love " << s.substr(0, ans) << "!" << endl;
}


Measured memory_bytes: 12892
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;

class C{
public:
	int x,y;
	C(int x,int y):x(x),y(y){}
};
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int w,h;

bool in(int x,int y){
	if(x<0 || y<0 || x>=w || y>=h) return false;
	return true;
}

long long int dist_goal[500][500],dist_spring[500][500];

const long long INF=10000000000LL;

int main()
{
/*	double m=1000000000000.0;
	for(int i=0;i<1000;i++){
		cout<<m<<endl;
		m/=2.0;
	}*/

	cin>>w>>h;
	int gx,gy,sx,sy;
	vector<string> M(h);
	vector<C> spring;
	long long num_normal=0;
	for(int i=0;i<h;i++){
		cin>>M[i];
		for(int j=0;j<M[i].size();j++){
			if(M[i][j]=='s'){sx=j;sy=i;num_normal++;}
			if(M[i][j]=='g'){gx=j;gy=i;}
			if(M[i][j]=='*'){spring.push_back(C(j,i));}
			if(M[i][j]=='.'){num_normal++;}
		}
	}

	for(int i=0;i<500;i++)
		for(int j=0;j<500;j++){
			dist_goal[i][j]=INF;
			dist_spring[i][j]=INF;
		}

	bool visit[500][500];
	memset(visit,false,sizeof(visit));

	queue<pair<C,int> > que;
	que.push(make_pair(C(gx,gy),0));

	while(!que.empty()){
		C now=que.front().first;
		int cost=que.front().second;
		que.pop();
		if(!in(now.x,now.y)) continue;
		if(M[now.y][now.x]=='#' || M[now.y][now.x]=='*') continue;
		if(visit[now.y][now.x]) continue;
		visit[now.y][now.x]=true;
		dist_goal[now.y][now.x]=cost;
		for(long long r=0;r<4;r++){
			que.push(make_pair(C(now.x+dx[r],now.y+dy[r]),cost+1));
		}
	}
	
	for(long long i=0;i<spring.size();i++)
		que.push(make_pair(C(spring[i].x,spring[i].y),0));
	memset(visit,false,sizeof(visit));
	while(!que.empty()){
		C now=que.front().first;
		long long cost=que.front().second;
		que.pop();
		if(!in(now.x,now.y)) continue;
		if(M[now.y][now.x]=='#') continue;
		if(visit[now.y][now.x]) continue;
		visit[now.y][now.x]=true;
		dist_spring[now.y][now.x]=cost;
		for(int r=0;r<4;r++){
			que.push(make_pair(C(now.x+dx[r],now.y+dy[r]),cost+1));
		}
	}

	const int NUM=1000;
	long double upper=1e20,lower=0.0;
	for(int t=0;t<NUM;t++){
		long double sum=0.0;
		long double E=(upper+lower)/2.0;
		vector<long double> work;
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				if(M[y][x]!='.' && M[y][x]!='s') continue;
				if(dist_goal[y][x]<INF) work.push_back(min((double)dist_goal[y][x],(double)dist_spring[y][x]+(double)E));
				else work.push_back(dist_spring[y][x]+E);
			}
		}
//		sort(work.begin(),work.end());
		for(int i=0;i<work.size();i++)
			sum+=work[i];
//		cout<<sum/num_normal<<endl;
		if(sum/num_normal<E) upper=E-1e-10;
		else lower=E+1e-10;
	}
//	cout<<min((double)dist_goal[sy][sx],(upper+lower)/2.0+dist_spring[sy][sx])<<endl;
	printf("%.13lf\n",min((double)dist_goal[sy][sx],(double)(upper+lower)/2.0+dist_spring[sy][sx]));
	return 0;
}

Measured memory_bytes: 9128
n, k = gets.split.map(&:to_i)
rsp = gets.split.map(&:to_i) + [0]
j = gets.chomp
te = ""
j.each_char.with_index do |c, i|
  win = (c == "r" ? "p" : (c == "s" ? "r" : "s"))
  if i >= k
    if te[i - k] == win
      # win = (win == "r" ? "s" : (c == "s" ? "p" : "r")) # ?
      win = "x"
    end
  end
  te << win
end
# p te
p te.tr("rspx", "0123").chars.map(&:to_i).map { |x| rsp[x] }.inject(&:+)


Measured memory_bytes: 9084
takoyaki_count = input()

takoyaki = input().split(" ")

takoyaki_int = [int(n) for n in takoyaki]

life_up = []

x_count = 0
for x in takoyaki_int:
    y_count = 0
    for y in takoyaki_int:
        if x_count < y_count:
            life_up.append(takoyaki_int[x_count] * takoyaki_int[y_count])
            
        y_count += 1
    
    x_count += 1
    
print(sum(life_up))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<stack>
#include<set>
#include<map>
#include<vector> 
#define ll long long
#define ms(x, n) memset(x,n,sizeof(x));
#define maxn 1010
using namespace std;

int main(){
	int x,y,ans=0;
	scanf("%d%d",&x,&y);
	for(int i=1;i<=x;i++){
		for(int j=1;j<=y;j++){
			int p=j%10,q=j/10;
			if(p>=2&&q>=2){
				if(p*q==i) ans++;
			}
		}
	}
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations as comb

n,m,x=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(n)]
smmin=None
for j in range(1,n+1):
    for z in comb(range(1,n+1),j):
        und=[0 for i in range(m)]
        sm=0
        for l in range(j):
            sm+=lst[z[l]-1][0]
            for k in range(1,m+1):
                und[k-1]+=lst[z[l]-1][k]
        for y in und:
            if y<x: break
        else :
            if not smmin: smmin=sm
            elif smmin>sm: smmin=sm
if not smmin: print(-1)
else : print(smmin)

Measured memory_bytes: 9164
s = input()

if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(1000000)
from collections import deque


h,w=map(int,input().split())
s = [list(input()) for i in range(h)]

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)

Measured memory_bytes: 3316
import sys
import os
# import math
# input = sys.stdin.readline

def int_array():
    return list(map(int, input().strip().split()))


def str_array():
    return input().strip().split()

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);x

def take_input():
	if os.environ.get("check"):
		sys.stdin = open('input.txt', 'r') 
		sys.stdout = open('output.txt', 'w')
		
take_input()
######################### TEMPLATE ENDS HERE #################################

for _ in range(int(input())):
    print("ACL", end="")

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

struct union_find{
  vector<int> r;
  union_find(int n){
    r=vector<int>(n,-1);
  }
  int root(int x){
    if(r[x]<0){
      return x;
    }else{
      return root(r[x]);
    }
  }
  bool unite(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b){
      return false;
    }else{
      if(r[a]>r[b]){
        swap(a,b);
      }
      r[a]+=r[b];
      r[b]=a;
      return true;
    }
  }
  int size(int x){
    return -r[root(x)];
  }
};
  
int main(){
  int n,m;
  cin>>n>>m;
  int a,b;
  union_find u(n);
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;
    b--;
    u.unite(a,b);
  }
  int M=1;
  for(int i=0;i<n;i++){
    M=max(u.size(i),M);
  }
  cout<<M<<endl;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;

    bool can = false;

    if (N % 2 == 0 && S.substr(0, N/2) == S.substr(N/2, N-1)) {
        can = true;
    }


    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;


}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

int a;

int main() {
    cout << fixed << setprecision(15);
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair <long int,long int>> student (N);
    vector<pair <long int,long int>> check (M);
    for(int i = 0;i < N;i++){
        cin >> student.at(i).FI;
        cin >> student.at(i).SE;
    }
    for(int i = 0;i < M;i++){
        cin >> check.at(i).FI;
        cin >> check.at(i).SE;
    }

    for(int i = 0;i < N;i++){
        long int test = LONGMAX;
        int answer;
        for(int j = 0;j < M;j++){
            if(test > abs(student.at(i).FI - check.at(j).FI) + abs(student.at(i).SE - check.at(j).SE)){
                test = abs(student.at(i).FI - check.at(j).FI) + abs(student.at(i).SE - check.at(j).SE);
                answer = j;
            }
        }
        cout << answer + 1 << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]


s = sum(a)
m = pow(10, 20)
b = 0
for i in range(N-1):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    #print(a[i])
print(m)

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w,ans=0,l[4]={0,0,1,-1},m[4]={1,-1,0,0};
    cin >> h >> w ;
    vector<vector<char>> maze(h,vector<char> (w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) cin >> maze[i][j];
    }
    function<int(int,int,int,int)> cost = [&](int sx,int sy,int gx,int gy){
        vector<vector<int>> dist(h,vector<int> (w,-1));
        queue<pair<int,int>> que;
        dist[sx][sy] = 0;
        que.push(make_pair(sx,sy));
        while(!que.empty()){
            pair<int,int> d = que.front();
            int x,y;
            tie(x,y)=d;
            que.pop();
            for(int i=0;i<4;i++){
                if(x+l[i]<0||h<=x+l[i]) continue;
                if(y+m[i]<0||w<=y+m[i]) continue;
                if(maze[x+l[i]][y+m[i]]=='#') continue;
                if(dist[x+l[i]][y+m[i]]!=-1) continue;
                dist[x+l[i]][y+m[i]] = dist[x][y]+1;
                que.push(make_pair(x+l[i],y+m[i]));
            }
        }
        return dist[gx][gy];
    };
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(maze[i][j]=='#') continue;
            for(int k=0;k<h;k++){
                for(int p=0;p<w;p++){
                    if(maze[k][p]=='#') continue;
                    ans = max(ans,cost(i,j,k,p));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256