akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include<string.h>
 
int main()
{
    int n,i,T=0,H=0,f;
    char t[101],h[101];
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s%s",t,h);
        f=strcmp(t,h);
        if(f==0){T+=1;H+=1;}
        else if(f>0)T+=3;
        else H+=3;
    }
    printf("%d %d\n",T,H);
    return 0;
}



Measured memory_bytes: 2100
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
a = [[int(j) for j in input().split()] for i in range(3)]
# print("a =" ,a)
# print(a)
n = int(input())
ans = [[0 for j in range(3)] for i in range(3)]
b = [int(input()) for i in range(n)]
# print("b =", b)
# print("ans =", ans)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            # print("a[i][j] =", a[i][j], "i = ", i, "j = ", j)
            ans[i][j] = 1

# print("ans =", ans)
if ans[0][0] == ans[0][1] == ans[0][2] == 1:
    print("Yes")
elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
    print("Yes")
elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
    print("Yes")

elif ans[0][0] == ans[1][0] == ans[2][0] == 1:
    print("Yes")
elif ans[0][1] == ans[1][1] == ans[2][1] == 1:
    print("Yes")
elif ans[0][2] == ans[1][2] == ans[2][2] == 1:
    print("Yes")

elif ans[0][0] == ans[1][1] == ans[2][2] == 1:
    print("Yes")
elif ans[0][2] == ans[1][1] == ans[2][0] == 1:
    print("Yes")

else:
    print("No")


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


using namespace std;







int n, a; 
long long ans, sum;


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a == 0)
			ans += (sum >> 1), sum = 0;
		else
			sum += a;
	}
	ans += (sum >> 1);
	cout << ans;
	return 0;
}

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

map<ll, ll> dp;
ll n, a, b, c, d;

ll f(ll n) {
    if (dp.count(n)) return dp[n];
    dp[n] = n * d;
    if (1e18 / n < d) dp[n] = 1e18;
    return dp[n] = min({
        dp[n],
        a + f(n / 2) + d * (n % 2),
        b + f(n / 3) + d * (n % 3),
        c + f(n / 5) + d * (n % 5),
        a + f((n + 1) / 2) + d * (2 - n % 2),
        b + f((n + 2) / 3) + d * (3 - n % 3),
        c + f((n + 4) / 5) + d * (5 - n % 5)
    });
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> a >> b >> c >> d;
        dp.clear();
        dp[0] = 0, dp[1] = d;
        cout << f(n) << endl;
    }
}

Measured memory_bytes: 4360
#include<iostream>
using namespace std;
bool a[1000001];
int main() {
	fill(a, a + 1000001, true);
	a[0] = false;
	a[1] = false;
	for (int i = 2; i <= 1000000;) {
		if (a[i]) {
			int j = 2;
			while (i*j <= 1000000) {
				a[i*j] = false;
				j++;
			}
		}
		if (i % 2 == 0)i++;
		else i += 2;
	}
	int n;
	while (cin >> n&&n != 0) {
		int sum = 0;
		if (a[n - 2]) sum++;
		for (int i = 3; i <= n / 2 ; i+=2) {
			if (a[i] && a[n - i]) sum++;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 4080
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    string s, t, u;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    cin >> u;

    if (u==s)
        --a;
    if (u==t)
        --b;

    cout << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <bits/stdc++.h>
using namespace std;

string to_string(string s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

int N;
int dp[111111];

int main()
{
    cin >> N;
    for (int i = 0; i <= N; i++)
    {
        dp[i] = 1000000;
    }
    dp[0] = 0;
    for (int i = 0; i <= N; i++)
    {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (int j = 6; i + j <= N; j *= 6)
        {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
            //cout << j << endl;
        }
        for (int j = 9; i + j <= N; j *= 9)
        {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
submits =  [list(input().split()) for i in range(M)]

penalties = [0 for _ in range(N)]
acs = [False for _ in range(N)]

for i, submit in enumerate(submits):
    p = int(submit[0])-1
    if acs[p]:
        continue
    if submit[1] == 'AC':
        acs[p] = True
    else:
        penalties[p] += 1

ac_num = sum(acs)
penalty_num = sum([p for i, p in enumerate(penalties) if acs[i]])

print("{} {}".format(ac_num, penalty_num))


Measured memory_bytes: 28412
def main():
  L1 = [1,3,5,7,8,10,12]
  L2 = [4,6,9,11]
  L3 = [2]
  ans = False
  x,y = map(int,input().split())
  if L1.count(x) == 1 and L1.count(y)==1:
    ans = True
  if L2.count(x) == 1 and L2.count(y) == 1:
    ans = True
  if L3.count(x) == 1 and L3.count(y) == 1:
    ans = True
  print("Yes" if ans else "No")
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for i in range(len(S)+1)]

dp[0][0] = 1

for i in range(len(S)):
    if S[i] == "?":
        c = -1
    else:
        c = int(S[i])
    for j in range(0, 10):
        if c != -1 and c != j:
            continue
        for k in range(0, 13):
            # dp[i+1][(10*k + j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
            dp[i+1][(10*k+j) % 13] = (dp[i+1][(10*k+j) % 13] + dp[i][k]) % mod
print(dp[len(S)][5])


Measured memory_bytes: 83160
#include<stdio.h>

int main(void){
	struct student{
		int n;
		double w;
		double h;
	}s[100];
	int c,f,i;
	
	c=0;
	while(scanf("%d,%lf,%lf",&s[c].n,&s[c].w,&s[c].h)!=EOF)c++;
	
	for(f=0,i=0;i<c;i++){
		if(s[i].w/(s[i].h*s[i].h)>=25.0){
			printf("%d\n",s[i].n);
			f=1;
		}
	}
	if(f==0)printf("NULL\n");
	
	return 0;
}
	
	
	
	

Measured memory_bytes: 628
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 500010
#define ll long long
using namespace std;
struct data{int x; double y;}d[N];
int n, op, cl, sum, x, sx;
double y, sy;
inline char gc(){
	static char now[1<<16], *S, *T;
	if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return EOF;}
	return *S++;
}
inline int read(){
	int x=0, f=1; char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=gc();}
	return x*f;
}
int main(){
	n=read(); sum=read();
	op=1; cl=0; sx=sy=0;
	for(int i=1; i<=n; i++){
		y=read(); x=read(); y*=x;
		sx+=x; sy+=y;
		while(sx>sum){
			if(sx-d[op].x<sum){sy-=d[op].y; d[op].y-=d[op].y/d[op].x*(sx-sum); d[op].x-=sx-sum; sx=sum; sy+=d[op].y;}
			else{sx-=d[op].x; sy-=d[op].y; op++;}
		}
		printf("%.10f\n", sy/sum);
		while(op<=cl&&y/x<d[cl].y/d[cl].x){
			y+=d[cl].y; x+=d[cl].x; cl--;
		}
		d[++cl].x=x; d[cl].y=y;
	}
	return 0;
}

Measured memory_bytes: 18304
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(llong& nNumN, llong& nNumK)
{
  cin >> nNumN >> nNumK;
}
  
llong fnMinRepNum(llong nNumN, llong nNumK)
{
  llong nRepNum = nNumN % nNumK;
  return min(nRepNum, nNumK - nRepNum);
}
  
int main()
{
  llong nNumN, nNumK;

  fnInput(nNumN, nNumK);
  cout << fnMinRepNum(nNumN, nNumK) << endl;

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e3+2,Mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
int n;
ll dp[N][N],a[N];
ll solve(int i,int j)
{
  if(i==j) return dp[i][j]=a[i];
  if(dp[i][j]!=-1) return dp[i][j];
  return dp[i][j]=max(a[i]-solve(i+1,j),a[j]-solve(i,j-1));
}
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  memset(dp,-1,sizeof(dp));
  solve(1,n);
  cout<<dp[1][n]<<endl;
  return 0;
}


Measured memory_bytes: 70784
/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num,int pos);
ll setbitt(ll num,ll pos);
ll resetbitt(ll num,int pos);
const ll mod =       1e9 + 7;
const ll N =     1e6 + 10;


 //.................___Start from here___.................//
//.................._____________________................//




int solve(){
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible";
    else cout<<"Impossible";
    cout<<endl;


    return 0;
}
int main(){
#ifndef ONLINE_JUDGE
  input;
  output;
#endif
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#endif
    int cs=1;
    int cn=1;
    //cin>>cs;
    while(cs--){
        solve();
        
    }
}


bool checkbitt(ll num,int pos){return (num>>pos) & 1;}
ll setbitt(ll num,ll pos){return (1<<pos) | num;}
ll resetbitt(ll num,int pos){if(!checkbitt(num,pos)) return num;else return (1<<pos)^num;}



Measured memory_bytes: 3604
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  string s;
  while(cin >> s){
    int N = s.size();
    int dp[2001] = {}; // dp[i] = [i, s.size())まで使ったときの最大の文字列
    static int prev[2001][2001] = {};
    memset(prev, -1, sizeof(prev));
    vector<int> indexes[26];
    REP(i, N) indexes[s[i] - 'A'].push_back(i);
    REP(i, N){
      // center
      if(dp[i] < dp[i + 1] + 1){
        dp[i] = dp[i + 1] + 1;
        prev[i + 1][i] = i + 1;
      }
      for(int j = i + 1; j < N; j++){
        //[i + 1, j + 1) = [i + 1, j]
        int cur = dp[j + 1];
        vector<int>& v = indexes[s[i] - 'A'];
        int idx = upper_bound(v.begin(), v.end(), j) - v.begin() - 1;  // j以下で最大
        if(0 <= idx && idx < v.size() && i + 1 <= v[idx] && dp[v[idx]] < cur + 2){
          dp[v[idx]] = cur + 2;
          prev[i + 1][v[idx]] = j + 1;
        }
      }
    }
    int max_c = 0;
    REP(i, N + 1) if(dp[max_c] < dp[i]) max_c = i;
    int curr = max_c;
    string ans;
    for(int i = N - 1; i >= 0; i--){
      if(prev[i + 1][curr] == -1){
      }else{
        if(i != curr) ans = s[i] + ans + s[curr];
        else ans = s[i];
        curr = prev[i + 1][curr];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 16888
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    a = list(map(int, input().split()))

    return N, a


def get_divisible_count(x: int) -> int:
    """
    2で何回割ることができるかを返す.

    Args:\n
        x (int): 整数

    Returns:\n
        int: 2で割ることができる回数
    """
    divisible_count = 0
    while x % 2 == 0:
        divisible_count += 1
        x /= 2
    return divisible_count


def main(N: int, a: list) -> tuple:
    """
    メイン処理.

    Args:\n
        N (int): 数列の長さ(1 <= N <= 10000)
        a (list): 数列(1 <= a_i <= 1000000000)

    Returns:\n
        tuple: [description]
    """
    ans = 0
    for n in range(N):
        ans += get_divisible_count(a[n])

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, a = get_input()

    # メイン処理
    main(N, a)


Measured memory_bytes: 10196
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 < b) System.out.println("a < b");
		if(a == b) System.out.println("a == b");
		if(a > b) System.out.println("a > b");

	}

}



Measured memory_bytes: 26140
#ifdef LOCAL
    #define debug_echo(expr) cout << expr;
#else
    #define debug_echo(expr)
#endif

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#include <vector>
template<class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o<<"{";
    bool f = false;
    for (const T &a: v)
        o<<(f?", ":"")<<a,
        f = true;
    o<<"}";
    return o;
}

int main() {
    int N;
    cin >> N;
    printf("ABC%03d\n", N);
}


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


int main(){
int a,b,c;
cin >> a >>b >>c;
  if(a+b ==c ||b+c ==a  ||a+c == b ){
    cout <<"Yes" << endl;
  }
  else{
    cout <<"No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		Map<Long, Long> shop =new TreeMap<Long, Long>();

		int N = sc.nextInt();
		int M = sc.nextInt();
		long min = 0;
		for (int i = 0; i < N; i++) {
			long key = sc.nextLong();
			long val = sc.nextLong();

			if (shop.containsKey(key)) {
				shop.put(key, shop.get(key) + val);
			} else {
				shop.put(key, val);
			}
		}

		for (Long item : shop.keySet()) {
			long lot = shop.get(item);
			if (lot >= M) {
				min += item*M;
				break;
			} else {
				M -= lot;
				min += item*lot;
			}
		}

		System.out.println(min);

	}
}


Measured memory_bytes: 67800
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[225816],b[225816];

int main(void){
	int n,m,i,j,ans=0;
	ll k;
	std::cin >> n >> m >> k;
	for(i=0; i<n; ++i){
		std::cin >> a[i+1];
		a[i+1] += a[i];
	}
	for(j=0; j<m; ++j){
		std::cin >> b[j+1];
		b[j+1] += b[j];
	}
	j = m;
	for(i=0; i<=n; ++i){
		while(a[i]+b[j]>k && j>0){
			// std::cout << i << " " << j << " " << a[i] << " " << b[j] << std::endl;
			--j;
		}
		if(a[i]+b[j]<=k){
			ans = std::max(ans,i+j);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 6716
#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
const int W = N * 2;
int p[W], fen[W], dp[N][N];
void add(int i,int v)
{
    for (; i < W; i += i & -i)
        fen[i] += v;
}
int qry(int i)
{
    int r = 0;
    for (; i; i ^= i & -i)
        r += fen[i];
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= 2 * n; ++i) {
        char c;
        int x;
        cin >> c >> x;
        p[x * 2 + (c == 'W')] = i;
        add(i,1);
    }
    p[0] = p[1] = W;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j)  {
            if (i || j) {
                int & d = dp[i][j];
                d = 1e9;
                if (i)
                    d = min(d, dp[i-1][j] + qry(p[2*i]-1) - (p[2*j+1] < p[2*i]));
                if (j)
                    d = min(d, dp[i][j-1] + qry(p[2*j+1]-1) - (p[2*i] < p[2*j+1]));
            }
            add(p[2*j+1],-1);
        }
        for (int j = 0; j <= n; ++j)
            add(p[2*j+1],1);
        add(p[2*i],-1);
    }
    cout << dp[n][n] << endl;
}


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

int main() {
  int n;
  cin >> n;
  int d[n];
  rep(i, n) cin >> d[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
#include<math.h>
const long p=1000000007;
using namespace std;
long long degree(long long a, long long k, long long p) {
  long long res = 1;
  long long cur = a;

  while (k) {
    if (k % 2) {
      res = (res * cur) % p;
    }
    k /= 2;
    cur = (cur * cur) % p;
  }
  return res;
}
int get_degree(long long n, long long p) { // returns the degree with which p is in n!
  int degree_num = 0;
  long long u = p;
  long long temp = n;

  while (u <= temp) {
    degree_num += temp / u;
    u *= p;
  }
  return degree_num;
}

long long combinations(int n, int k, long long p) {
  int num_degree = get_degree(n, p) - get_degree(n - k, p);
  int den_degree = get_degree(k, p);

  if (num_degree > den_degree) {
    return 0;
  }
  long long res = 1;
  for (long long i = n; i > n - k; --i) {
    long long ti = i;
    while(ti % p == 0) {
      ti /= p;
    }
    res = (res * ti) % p;
  }
  for (long long i = 1; i <= k; ++i) {
    long long ti = i;
    while(ti % p == 0) {
      ti /= p;
    }
    res = (res * degree(ti, p-2, p)) % p;
  }
  return res;
}
int main(){
   int X,Y;
   std::cin>>X>>Y;
   if((X+Y)%3!=0){
       std::cout<<0;
       
   }
   else if((X+Y)/3>X||(X+Y)/3>Y){
       std::cout<<0;
   }
   else{
       
       
       std::cout<<combinations((X+Y)/3,(2*X-Y)/3 , p) ;
   }
    return 0;
}

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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

string s; 
ll m, a, r, c, h;
ll D[5];
int A[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2}; 
int B[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int C[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    F0R(i, n) {
        cin >> s;
        if (s[0] == 'M') m++;
        if (s[0] == 'A') a++;
        if (s[0] == 'R') r++;
        if (s[0] == 'C') c++;
        if (s[0] == 'H') h++;
    }
    D[0] = m; D[1] = a; D[2] = r; D[3] = c; D[4] = h;
    ll ans = 0;
    F0R(i, 10) {
        ans += D[A[i]] * D[B[i]] * D[C[i]];
    }
    cout << ans << nl;
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class hawawa
{
  static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };

  static void Main()
  {
    Console.SetOut(sw);
    solve();
    Console.Out.Flush();
  }

  static void solve()
  {
    Scanner scanner = new Scanner();
    long n = scanner.nextInt(), y = scanner.nextInt();
    for(long i = 0; i <= n; i++)
    {
      for(long j = 0; j <= n - i; j++)
      { 
        if (1000 * i + 5000 * j + 10000 * (n - i - j) == y)
        {
          Console.WriteLine("{0} {1} {2}", n - i -j, j, i);
          return;
        }
      }
    }
    Console.WriteLine("-1 -1 -1");
  }
}

class Scanner
{
  string[] s;
  int i;


  char[] cs = new char[] { ' ' };

  public Scanner()
  {
    s = new string[0];
    i = 0;
  }

  public string next()
  {
    if (i < s.Length) return s[i++];
    string st = Console.ReadLine();
    while (st == "") st = Console.ReadLine();
    s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
    i = 0;
    return next();
  }

  public int nextInt()
  {
    return int.Parse(next());
  }

  public long nextLong()
  {
    return long.Parse(next());
  }

  public double nextDouble()
  {
    return double.Parse(next());
  }

}

class Printer : StreamWriter
{
  public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
  public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
  public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.Scanner;

// C

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		String line2 = sc.nextLine();

		int[] a = new int[26]; // 出現回数格納用の配列
		int[] b = new int[26]; // 出現回数格納用の配列

		Arrays.fill(a, 0);
		Arrays.fill(b, 0);

		// 文字数違うなら終わり
		if(line1.length() != line2.length()){
			System.out.println("No");
			return;
		}


		for(int i = 0; i < line1.length(); i++){
			char ch = line1.charAt(i);
			if(ch == 'a'){
				a[0]++;
			}
			else if(ch == 'b'){
				a[1]++;
			}
			else if(ch == 'c'){
				a[2]++;
			}
			else if(ch == 'd'){
				a[3]++;
			}
			else if(ch == 'e'){
				a[4]++;
			}
			else if(ch == 'f'){
				a[5]++;
			}
			else if(ch == 'g'){
				a[6]++;
			}
			else if(ch == 'h'){
				a[7]++;
			}
			else if(ch == 'i'){
				a[8]++;
			}
			else if(ch == 'j'){
				a[9]++;
			}
			else if(ch == 'k'){
				a[10]++;
			}
			else if(ch == 'l'){
				a[11]++;
			}
			else if(ch == 'm'){
				a[12]++;
			}
			else if(ch == 'n'){
				a[13]++;
			}
			else if(ch == 'o'){
				a[14]++;
			}
			else if(ch == 'p'){
				a[15]++;
			}
			else if(ch == 'q'){
				a[16]++;
			}
			else if(ch == 'r'){
				a[17]++;
			}
			else if(ch == 's'){
				a[18]++;
			}
			else if(ch == 't'){
				a[19]++;
			}
			else if(ch == 'u'){
				a[20]++;
			}
			else if(ch == 'v'){
				a[21]++;
			}
			else if(ch == 'w'){
				a[22]++;
			}
			else if(ch == 'x'){
				a[23]++;
			}
			else if(ch == 'y'){
				a[24]++;
			}
			else if(ch == 'z'){
				a[25]++;
			}
		}

		for(int i = 0; i < line2.length(); i++){
			char ch = line2.charAt(i);
			if(ch == 'a'){
				b[0]++;
			}
			else if(ch == 'b'){
				b[1]++;
			}
			else if(ch == 'c'){
				b[2]++;
			}
			else if(ch == 'd'){
				b[3]++;
			}
			else if(ch == 'e'){
				b[4]++;
			}
			else if(ch == 'f'){
				b[5]++;
			}
			else if(ch == 'g'){
				b[6]++;
			}
			else if(ch == 'h'){
				b[7]++;
			}
			else if(ch == 'i'){
				b[8]++;
			}
			else if(ch == 'j'){
				b[9]++;
			}
			else if(ch == 'k'){
				b[10]++;
			}
			else if(ch == 'l'){
				b[11]++;
			}
			else if(ch == 'm'){
				b[12]++;
			}
			else if(ch == 'n'){
				b[13]++;
			}
			else if(ch == 'o'){
				b[14]++;
			}
			else if(ch == 'p'){
				b[15]++;
			}
			else if(ch == 'q'){
				b[16]++;
			}
			else if(ch == 'r'){
				b[17]++;
			}
			else if(ch == 's'){
				b[18]++;
			}
			else if(ch == 't'){
				b[19]++;
			}
			else if(ch == 'u'){
				b[20]++;
			}
			else if(ch == 'v'){
				b[21]++;
			}
			else if(ch == 'w'){
				b[22]++;
			}
			else if(ch == 'x'){
				b[23]++;
			}
			else if(ch == 'y'){
				b[24]++;
			}
			else if(ch == 'z'){
				b[25]++;
			}
		}

		// 昇順にソート
		Arrays.sort(a);
		Arrays.sort(b);
		String ans = "";

		for(int i=0; i < 26; i++){
			if(a[i] != b[i]){
				ans = "No";
				break;
			}
			if(i == 25){
				ans = "Yes";
			}
		}

			System.out.println(ans);
	}
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,q;
  ll t=0;
  cin >> n;
  vector<int> a(100000,0);
  rep(i,n){
      int x;
      cin >> x;
      a[x]++;
      t+=x;
  }
  cin >> q;
  while(q--) {
    int b,e;
    cin >> b >> e;
    t+=a[b]*(e-b);
    a[e]+=a[b];
    a[b]=0;
    cout << t << endl;
  }
}

Measured memory_bytes: 3728
N = list(input())
m = 0
cnt = 0
for x in N:
    
    if x == 'A' or x == 'C' or x == 'G' or x == 'T':
        cnt += 1
    else:
        m = max(cnt, m)
        cnt = 0

m = max(cnt, m)

print(m)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

LL n; int tot=0;
deque <int> le,re;
inline void solve(LL n) {
    if(n==1) return;
    solve(n>>1);
    le.push_front(++tot);
    re.push_front(tot);
    if(n&1) {
        le.push_front(++tot);
        re.push_back(tot);
    }
}
int main() {
    cin>>n; solve(n+1);
    cout<<le.size()+re.size()<<endl;
    for(int i=0;i<le.size();++i) cout<<le[i]<<" ";
    for(int i=0;i<re.size();++i) cout<<re[i]<<" ";
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True)
x = [0] * M
p = [x for x in range(M)]

cnt = 0
cntIN = M
for a, b in AB:
    i = M-a

    s = []
    while i >= 0 and p[i] != i:
        s.append(i)
        i = p[i]
    for j in s:
        p[j] = i - 1

    if i >= 0:
        x[i] = b
        p[i] = i - 1
        cntIN -= 1            
        if cntIN <= 0:
            break

print(sum(x))


Measured memory_bytes: 32704
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int A,B,C;

int main()
{
  cin >> A >> B >> C;
  cout << min(C, B / A) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(void)
{
	long long x, y;
	cin >> x >> y;
	auto dif = abs(x - y);
	if (dif <= 1)
	{
		cout << "Brown" << endl;
	}
	else
	{
		cout << "Alice" << endl;
	}
	return 0;
}


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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<pair<int, int>> cnt(N + 1, pair<int, int>(0, 0));
    for (int i = 1; i <= N; i++)
    {
        if (S[i - 1] == 'W')
        {
            cnt[i].first = cnt[i - 1].first + 1;
            cnt[i].second = cnt[i - 1].second;
        }
        else
        {
            cnt[i].first = cnt[i - 1].first;
            cnt[i].second = cnt[i - 1].second + 1;
        }
    }
    int ans = N;
    for (int i = 1; i <= N; i++)
    {
        int tmp = 0;
        tmp += cnt[i - 1].first;
        tmp += cnt[N].second - cnt[i].second;
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

using namespace std;
int const MAXN =1e5;


int main(void){
	int t,k;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> t >> k;
	long long best[MAXN];
	int nums[MAXN];
	for(int i=0;i < t;i++) cin >> nums[i];
	
	for(int l=0;l < t;l++) best[l]=4294967296;
	//cout << best[1] << " HERE" << "\n";
	best[0] = 0;
	for(int i=0;i<t;i++){
		for(int j=1;j<=min(i, k);j++){
			//cout << "CHECKING " << j << " " << i << " " << best[i-j]<<"\n";
			best[i] = min(best[i], best[i-j]+abs(nums[i-j]-nums[i]));
		}
		
		
		
	}
	//for(int ans=0; ans < t;ans++) cout << best[ans] << " " << t<< "\n";
	cout << best[t-1] << "\n";
	
		
	
}

 


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll N, A, B;
  cin >> N >> A >> B;

  ll kaisuu = N / (A + B);
  ll amari = N % (A + B);
  if (kaisuu == 0) {
    cout << min(A, N) << endl;
  } else {
    cout << kaisuu * A + min(amari, A);
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vp vector<pair<int,int>>
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(),x.end()
#define cmp(t,x) [](const t& _a,const t& _b) {return _a.x<_b.x;}
#define pq priority_queue


int main(){
    ios::sync_with_stdio(true);
    cin.tie(NULL);
    int x;cin>>x;
    if (x==1) cout<<0;
    else cout<<1;
    return 0;
}


Measured memory_bytes: 3612
from collections import Counter

N, X, Y = map(int, input().split())
g = [[float("inf")] * N for _ in range(N)]

for i in range(1, N+1):
    for j in range(1, N+1):
        g[i-1][j-1] = min([abs(j-i), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j)])

c = Counter()
for i in range(N):
    c.update(g[i][:i])

for i in range(1, N):
    print(c[i])

Measured memory_bytes: 139784
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long mod = 1e9+7;
int main(void){
    int N;
    cin >> N;
    int P[1001] = {0};
    long long ans = 1;
    for(int i=2;i<=N;i++){
        int M = i;
        for(int j=2;j*j<=N;j++){
            if(M % j == 0){
                while(M % j == 0){
                    M /= j;
                    P[j]++;
                }
            }
        }
        if(M != 1){
            P[M]++;
        }
    }
    for(int i=2;i <= N;i++){
        if(P[i]){
            ans = (ans * (P[i] + 1)) % mod;
        }
    }
    cout << ans << endl;
}


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


int main()
{
    int n;cin>>n;
    if(n < 10) cout << n << endl;
    else if(n < 100) cout << ((n - 1)/11+1)*11 << endl;
    else cout << ((n - 1)/111+1)*111 << endl;
    return 0;
}

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

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

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


def main():
    s = S()
    l = len(s)
    fm = {}
    fm[''] = -1
    def f(s):
        if s in fm:
            return fm[s]
        l = len(s)
        r = -1
        if l > 5 and s[1] in '(?' and s[-1] in ')?':
            if s[0] in 'R?':
                for i in range(3,l-2):
                    if s[i] not in ',?':
                        continue
                    tl = f(s[2:i])
                    tr = f(s[i+1:-1])
                    if tl >= 0 and tr >= 0 and r < tr:
                        r = tr
            if s[0] in 'L?':
                for i in range(3,l-2):
                    if s[i] not in ',?':
                        continue
                    tl = f(s[2:i])
                    tr = f(s[i+1:-1])
                    if tl >= 0 and tr >= 0 and r < tl:
                        r = tl
        ff = True
        if s[0] == '0' and l > 1:
            ff = False
        for tc in 'RL,()':
            if tc in s:
                ff = False
                break
        if ff:
            r = int(s.replace('?', '9'))
        fm[s] = r
        return r

    r = f(s)
    if r < 0:
        return 'invalid'

    return r


print(main())



Measured memory_bytes: 9100
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  putStrLn $ if all p as then "APPROVED" else "DENIED"

p :: Int -> Bool
p k = odd k || k `mod` 3 == 0 || k `mod` 5 == 0

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, K;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    ll ans = 0;
    while(N--) {
        ll x;
        cin >> x;
        ans += min(x, K - x);
    }
    cout << ans * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var line;
while (line = lines.shift()) {
    var nums = line.split(' ');
    var n = +nums[0];
    var m = +nums[1];
    if (n + m == 0) break;

    var p = [];
    for (var i = 0; i < n; i++) {
        p.push(i + 1);
    }

    while (p.length > 1) {
        for (var i = 0; i < m - 1; i++) {
            p.push(p.shift());
        }
        p.shift();
    }
    console.log(p[0]);
}

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

int main() {
	int n;
	cin >> n;
	long long ans=1,ans2=1;
	int a;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		ans*=3;
		if(a%2==0)
		ans2*=2;
	}
	cout << ans-ans2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

const li max_n = 300;
const li mod = 1e9 + 7;

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

    li n, m;
    cin >> n >> m;

    vector<vector<li>> dp(n + 1, vector<li>(n + 1, 0));
    // dp[# 1 -> v][# v -> 1]
    dp[1][1] = 1;

    for (int step = 0; step < m; ++step) {
        vector<vector<li>> ndp(n + 1, vector<li>(n + 1, 0));

        for (int x = 0; x <= n; ++x) {
            for (int y = 0; y <= x; ++y) {
                ndp[x][x] += dp[x][y] * y % mod;
                ndp[x][x] %= mod;
            }
            for (int y = 0; y < x; ++y) {
                ndp[x][y] += dp[x][y] * (x - y) % mod;
                ndp[x][y] %= mod;

                if (x > 0 && x - 1 >= y) {
                    ndp[x][y] += dp[x - 1][y] * (n - (x - 1)) % mod;
                    ndp[x][y] %= mod;
                }
            }

        }

        dp = ndp;
    }
    cout << dp[n][n] << endl;
    return 0;
}


Measured memory_bytes: 1752
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int n,x;
class ABC148D {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;
		map<int,set<int>> pos;
		f(i,0,n)
		{
			in >> x;
			pos[x].insert(i);
		}
		if(!pos.count(1))
		{
			out << "-1\n";
			return;
		}
		int cur=-1,req=1;
		while(pos.count(req))
		{
			auto it=pos[req].upper_bound(cur);
			if(it==pos[req].end())
				break;
			cur=*it;
			req++;
		}
		out << n-req+1 << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ABC148D solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 28416
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{
    public static void main(String[] args) throws IOException
    {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int[][] paper = new int[14][14];
		// assume we use 14*14 cells, then finally ignore the 0 to 1 and 12 to 13
		int count=0, max=0;
		
		while((s = br.readLine())!=null && !s.isEmpty())
		{
			int x = Integer.parseInt(s.split(",")[0]);
			int y = Integer.parseInt(s.split(",")[1]);
			int size = Integer.parseInt(s.split(",")[2]);
			
			drop(x+2,y+2,size,paper); // as we use 14*14 paper(but just assumes it as 10*10)
		}
		for(int i=2; i<12; i++)
			for(int j=2; j<12; j++){
				if(paper[i][j]==0) count++;
				if(paper[i][j] > max) max = paper[i][j];
			}
		System.out.println(count);
		System.out.println(max);
	}
		
	private static void drop(int x, int y, int size, int[][] paper)
	{
		if(size==1){ 
			for(int i=x-1; i<x+2; i++) paper[y][i]++;
			for(int i=y-1; i<y+2; i++) paper[i][x]++;
			paper[y][x]--;
		} else if(size==2) {
			for(int i=x-1; i<x+2; i++)
				for(int j=y-1; j<y+2; j++)
					paper[j][i]++;
		} else {
			for(int i=x-2; i<x+3; i++) paper[y][i]++;
			for(int i=x-1; i<x+2; i++) {
				paper[y+1][i]++;
				paper[y-1][i]++;
			}
			for(int i=y-2; i<y+3; i++) paper[i][x]++;
				paper[y+1][x]--;
				paper[y-1][x]--;
				paper[y][x]--;
		}
	}
}

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, M, i, a[100], b[100], link[10][10]={0}, ans=0, judge;

    cin >> N >> M;

    vector<ll> v(N);

    for(i=1; i<=M; i++){
        cin >> a[i] >> b[i];
        link[a[i]][b[i]] = 1;
    }

    for(i=0; i<N; i++){
        v[i] = i+1;
    }

    do{
        judge = 1;

        for(i=0; i<N-1; i++){
            if(link[v[i]][v[i+1]]==0 && link[v[i+1]][v[i]]==0){
                judge = 0;
            }
        }
        if(v[0]!=1) judge = 0;

        if(judge==1) ans++;

    }while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
sign = []
for i in range(N):
    sign.append(A[i] > 0)
if sign.count(False) % 2 == 0:
    result = 0
    for i in range(N):
        result += abs(A[i])
else:
    result = 0
    for i in range(N):
        result += abs(A[i])
    result -= 2 * min(list(map(abs, A)))
print(result)

Measured memory_bytes: 14224
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <bitset>

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

using namespace std;

int main() {
	int N, A = 0;
	scanf("%d", &N);
	vector<int> a(N);
	rep(i, N) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end(), greater<int>());

	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) A += a[i];
		else A -= a[i];
	}

	printf("%d", A);
}




Measured memory_bytes: 3260
H,W,N=map(int,input().split())
D=dict()
da=[-1,-1,-1,0,0,0,1,1,1]
db=[-1,0,1,-1,0,1,-1,0,1]
for i in range(N):
    a,b=map(int,input().split())
    for j in range(9):
        na=a+da[j]
        nb=b+db[j]
        if 1<na<H and 1<nb<W:
            if (na,nb) in D:
                D[(na,nb)]+=1
            else:
                D[(na,nb)]=1
ans=[0 for i in range(10)]
for i in D:
    ans[D[i]]+=1
tmp=sum(ans)
ans[0]=(H-2)*(W-2)-tmp
for i in ans:
    print(i)


Measured memory_bytes: 166484
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	string a,b;
	cin>>a>>b;
	rep(_,a.size()){
	    a=a.back()+a.substr(0,a.size()-1);
	    if(a==b){
	        cout<<"Yes"<<endl;
	        return 0;
	    }
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int N[1000];
  int i,j;
  int total = 0;
  for(i = 0;i < 1000;i++){
    total += i+1;
    N[i] = total;
  }

  i =1;
  while(1){
    for(j = 0;j < 999;j++){
      if((N[j]-i) == a){
        if((N[j+1]-i) == b){
          cout << i << endl;
          return 0;
        }
      }
    }
      i++;
  }
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;

public class Main {
  private static void solve() {
    int n = ni();
    int[] a = na(n);
    
    long[] sum = new long[n + 1];
    for (int i = 0; i < n; i ++) {
      sum[i + 1] = sum[i] + a[i];
    }
    
    Map<Long, Long> count = new HashMap<>();
    for (long v : sum) {
      if (!count.containsKey(v)) {
        count.put(v, 0L);
      }
      
      count.put(v, count.get(v) + 1);
    }

    long ret = 0;
    for (Map.Entry<Long, Long> entry : count.entrySet()) {
      long v = entry.getValue();
      ret += v * (v - 1) / 2;
    }
    System.out.println(ret);
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 60352
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')
 
const [head, ...rest] = stdin.split('\n').filter(e=>e)
 
const [n, m] = head.split(' ').map(Number)
 
const ka = rest.map(e=>e.split(' ').map(Number))
 
let commons = []
 
ka.forEach((e,i)=>{
  const [k, ...a] = e
  
  if(i === 0){
    commons = a
  } else {
    const filtered = a.filter(v => {
      return commons.indexOf(v) > -1
    })
 
    commons = filtered
  }
})
 
console.log(commons.length)

Measured memory_bytes: 7628
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,time=0,x=0,y=0,time1,x1,y1,sum,sum1,flag,z=0;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d%d",&time1,&x1,&y1);
        sum=time1-time;
        sum1=x1+y1-x-y;
        flag=(x1+y1)%2;
        if(sum>=sum1&&(time1%2==flag));
        else z=1;
        time=time1;
        x=x1;
        y=y1;
    }
    if(z==0)
    printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256