akhauriyash/Code-Regression huggingface dataset:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, k = inpl()
a = inpl()
data = [[abs(i), i < 0] for i in a]
all_minus = 0
for t in data:
    if t[1]:
        all_minus += 1
if all_minus == n and k%2!=0:
    ans = 1
    data.sort()
    for i in range(k):
        ans = ans * data[i][0] % mod
    ans=ans*((-1)%mod)
    print(ans % mod)
    exit()
data.sort(reverse=True)
last_minus = 0
last_plus = 0
ans = 1
minus_amount = 0
for i in range(k):
    elem, sign = data[i][0], data[i][1]
    if elem == 0:
        print(0)
        exit()
    ans = ans * elem % mod
    minus_amount += sign
    if sign:
        last_minus = elem
    else:
        last_plus = elem
if minus_amount % 2 == 0:
    print(ans%mod)
    exit()
if n==k:
    print(-ans % mod)
    exit()
tmp_plus = 0
tmp_minus = 0
for i in range(k, n):
    elem, sign = data[i][0], data[i][1]
    if last_plus and sign and not tmp_minus:
        tmp_minus = elem
    elif last_minus and not sign and not tmp_plus:
        tmp_plus = elem
if tmp_plus == 0 and tmp_minus == 0:
    ans = 0
elif last_plus == 0:
    ans = ans * pow(last_minus, mod - 2, mod) * tmp_plus % mod
elif last_minus == 0:
    ans = ans * pow(last_plus, mod - 2, mod) * tmp_minus % mod
elif tmp_plus * last_plus > tmp_minus * last_minus:
    ans = ans * pow(last_minus, mod - 2, mod) * tmp_plus % mod
else:
    ans = ans * pow(last_plus, mod - 2, mod) * tmp_minus % mod
print(ans)


Measured memory_bytes: 112936
#define _USE_MATH_DEFINES
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <nmmintrin.h>
#include <immintrin.h>
#include <mmintrin.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,P) scanf("%d %d %d %d",&n,&m,&o,&P)
#define SINT5(n,m,o,P,q) scanf("%d %d %d %d %d",&n,&m,&o,&P,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1'010'000'000; // 0x3C33'6080
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second


int main() {
	int r;
	cin >> r;
	cout << 3 * r*r <<endl;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::mem;

fn main() {
    input! {
        x: isize,
        y: isize,
    }

    const D: isize = 1000000007;
    let mut b = 2 * x - y;
    let mut a = 2 * y - x;
    let ans;

    if b >= 0 && a >= 0 && b % 3 == 0 && a % 3 == 0 {
        b = b / 3;
        a = a / 3;
        if b < a {
            mem::swap(&mut a, &mut b);
        }
        //println!("a {} b {}", a, b);
            
        let child = (1..a+b+1).fold(1, |product, x| product*x%D);
        let mother = (1..a+1).fold(1, |product, x| product*x%D) 
            * (1..b+1).fold(1, |product, x| product*x%D) % D;
        //println!("child {} mother {}", child, mother);
        ans = child * modinv(mother, D) % D;
    } else {
        ans = 0;
    }

    println!("{}", ans);
}

fn modinv(mut a: isize, m: isize) -> isize {
    let mut b : isize= m;
    let mut u : isize= 1;
    let mut v = 0;

    while b != 0 {
        let t = a / b;
        a -= t * b; mem::swap(&mut a, &mut b);
        u -= t * v; mem::swap(&mut u, &mut v);
    }

    u %= m;

    if u < 0 {
        u += m;
    }
    u
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int n,k;
	cin>>n>>k;
	if(n>=13)
	{
		cout<<k;
	}
	if(n>=6 && n< 13)
	{
		cout<< k/2 ;
	}
	if(n<6)
	{
		cout<<"0";
	}
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vector<array<int, 3>> blks(n);
  rep(i,0,n) cin >> blks[i][0] >> blks[i][1] >> blks[i][2];
  sort(all(blks), [&](auto a, auto b) { return a[0]+a[1] < b[0]+b[1]; });

  ll ans = 0;
  vvl dp(11234, vl(n+1));

  rep(i,0,11234) {
    rep(j,0,n) {
      if (blks[j][1] >= i) {
        if (i+blks[j][0] < 11234) ckmax(dp[i+blks[j][0]][j+1], dp[i][j]+blks[j][2]);
        else ckmax(ans, dp[i][j]+blks[j][2]);
      }
      ckmax(dp[i][j+1], dp[i][j]);
    }
  }

  rep(i,0,11234) ckmax(ans, *max_element(all(dp[i])));
  cout << ans << '\n';
}

Measured memory_bytes: 88576
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vll vector<ll>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
const ll INF =1LL << 62;
int main(){
  int A,B; cin >> A >> B;
  if(A ==B){
    cout << A+B<< endl;
    return 0;
  }
  cout << (A>=B ? A+A-1:B+B-1) << endl;
}


Measured memory_bytes: 256
import numpy as np
import itertools
comb = itertools.combinations

H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
C = [[1 if C[k][j] == '#' else 0 for j in range(W)] for k in range(H)]
C = np.array(C)
harray = np.arange(H)
warray = np.arange(W)

Corig = C.copy()

ans = 0
for h in range(H+1):
  for w in range(W+1):
    # import pdb;pdb.set_trace()
    Hc = list(comb(harray, h))
    Wc = list(comb(warray, w))
    for hc in Hc:
      for wc in Wc:
        C = Corig.copy()
        for hcc in hc:
            C[hcc,:] = 0
        for wcc in wc:
          C[:,wcc] = 0
        # print('-----')
        # print(hc, wc, C)
        # print('-----')
        if np.sum(C) == K:
          ans += 1
print(ans)

Measured memory_bytes: 27256
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static int[] dx, dy;
    public static void Main()
    {
        dx = new int[] { 0, 1, 0, -1 };
        dy = new int[] { 1, 0, -1, 0 };
        var d = new Dictionary<int, int>();
        goBfs(d);
        string s;
        for (; (s = Console.ReadLine()) != null;)
        {
            s = s.Replace(" ", "");
            Console.WriteLine(d[int.Parse(s)]);
        }
    }
    static void goBfs(Dictionary<int, int> dd)
    {
        dd[1234567] = 0;
        var q = new Queue<int>();
        q.Enqueue(1234567);
        while (q.Count() > 0)
        {
            var t = q.Dequeue();
            foreach (var x in getNext(t))
                if (!dd.ContainsKey(x))
                {
                    dd[x] = dd[t] + 1;
                    q.Enqueue(x);
                }
        }
    }
    static IEnumerable<int> getNext(int n)
    {
        var s = n.ToString();
        if (s.Length == 7) s = "0" + s;
        var w = new string[2, 4];
        var p = 0;
        var ix = 0;
        var iy = 0;
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 4; j++)
            {
                w[i, j] = s[p++].ToString();
                if (w[i, j] == "0") { ix = i; iy = j; }
            }
        for (int i = 0; i < 4; i++)
        {
            var nx = ix + dx[i];
            var ny = iy + dy[i];
            if (nx >= 0 && nx < 2 && ny >= 0 && ny < 4)
            {
                w[ix, iy] = w[nx, ny];
                w[nx, ny] = "0";
                var wt = "";
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 4; k++)
                        wt += w[j, k];
                w[nx, ny] = w[ix, iy];
                w[ix, iy] = "0";
                yield return int.Parse(wt);
            }
        }
    }
}



Measured memory_bytes: 24072
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  bool flag = true;
  int cnt = 0;
  if (s[0] == 'A' && islower(s[1]) && islower(s[s.size() - 1])) {
    for (int i = 2; i < s.size(); i++) {
      if (s[i] == 'C') cnt++;
      if (isupper(s[i]) && s[i] != 'C') flag = false;
    }
  }
  else flag = false;
  if (cnt != 1) flag = false;
  if (flag) cout << "AC" << endl;
  else cout << "WA" << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

divisor = 10^9 + 7 :: Integer

main :: IO ()
main = do
  (h,w,a,b) <- listToTuple4 . map read . words <$> getLine :: IO (Int,Int,Int,Int)

  let
    x = array (0,w+h-2) $ (0,1) : [(i,(x!(i-1) * (fromIntegral i))`mod`divisor) | i<-[1..w+h-2]]
    y = array (0,w+h-2) $ (0,1) : [(i,(y!(i-1) * (powerMod (fromIntegral i) (divisor-2) divisor))`mod`divisor) | i<-[1..w+h-2]]

  print $ foldl1 (\a b -> mod (a+b) divisor) $ [(x!(i-1+h-a-1) * y!(h-a-1) * y!(i-1) * (x!(w-i+a-1) * y!(a-1) * y!(w-i))) `mod` divisor | i<-[b+1..w]]


{-- n^p mod m --}
powerMod :: Integral a => a -> a -> a -> a
powerMod n 0 m = 1
powerMod n 1 m = n `mod` m
powerMod n p m = (k * k * (if mod p 2 == 0 then 1 else n)) `mod` m
  where
    k = powerMod n (div p 2) m


Measured memory_bytes: 42876
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll n,m;
  cin >>n>>m;
  vector<ll> vec(m);
  ll key=0;
  rep(i,m){
    cin >>vec[i];
    key+=vec[i];
  }
  if(key>n){
    cout <<-1<<endl;
  }else{
    cout <<n-key<<endl;
  } 
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> a;
vector<int> num={1000,2,5,5,4,5,6,3,7,6};
vector<string> dp(10010);

bool large(string& s, string& t){
  if(s.size()!=t.size()){ return s.size()>t.size(); }
  return s>t;
}

string rec(int n){
  if(dp[n]!=""){ return dp[n]; }
  if(n==0){ return ""; }
  string ret="";
  for(auto to:a){
    if(n-num[to]>=0){
      string now = (char)(to+'0')+rec(n-num[to]);
      if(now.back()=='x'){ continue; }
      if(large(now,ret)){ ret = now; }
    }
  }
  if(ret==""){ ret = "x"; }
  return dp[n] = ret;
}

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

  rep(i,m){ int k; cin >> k; a.emplace_back(k); }  
  string ans=rec(n);
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
struct edge{
    ll des;
    ll w;
};
 
struct node{
    ll id;
    ll dp;
};
 
ll n,m;
vector <edge> adj[10007];
ll ans;
bool mark[10007];
ll Min[10007];
 
bool operator<(node a,node b)
{
    return a.dp>=b.dp;
}
 
void prim()
{
    fill(Min,Min+10007,1e10);
 
    priority_queue <node> q;
 
    node nd;
    nd.id=0;
    nd.dp=0;
    q.push(nd);
 
    for(int i=1;i<n;i++)
    {
        nd.id=i;
        nd.dp=1e8;
        q.push(nd);
    }
 
    while(q.size()>0)
    {
        nd=q.top();
        q.pop();
        ll u=nd.id;
 
        if(mark[u])
            continue;
 
        Min[u]=nd.dp;
        ans+=nd.dp;
        mark[u]=1;
 
        for(ll i=0;i<adj[u].size();i++)
        {
            ll v=adj[u][i].des;
            ll val=adj[u][i].w;
            if(Min[v]>val)
            {
                Min[v]=val;
                node nn;
                nn.id=v;
                nn.dp=val;
                q.push(nn);
            }
        }
    }
}
 
int main()
{
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        edge e;
        cin>>x>>y>>e.w;
        e.des=y;
        adj[x].push_back(e);
        e.des=x;
        adj[y].push_back(e);
    }
    prim();
    cout<<ans<<endl;
}

Measured memory_bytes: 7564
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<map>

using namespace std;

int main(){
	int n;
	cin>>n;
	map<int,int> anko;
	for(int i=0;i<n;++i){
		int x; cin >> x;
		anko[x]++;
	}
	int ans=anko.size();
	cout << ans << endl;
	return 0;		
}
 

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

int main(void) {
    int X,A,B;cin>>X>>A>>B;
    if (B - A <= 0) cout << "delicious" << endl;
    else if (B - A > 0 && B - A <= X) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())

arr = [ int(input()) for i in range(N)]

arr.sort()
cnt = 0
num = 1

a = arr[0]

for i in range(1,N):
  if arr[i] == a:
    num += 1
  else:
    if num % 2 == 1:
      cnt += 1
    num = 1
    a = arr[i]
if num % 2 == 1:
  cnt += 1

print(int(cnt))


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

int gcd(int a,int b) {
    if (b==0) {
        return a;
    }
    return gcd(b,a%b);
}
int main() {
    int N,X;
    cin>>N>>X;
    int x[N+1];
    int dis[N];
    for (int i=0; i<N; i++) {
        dis[i]=0;
    }
    for (int i=0; i<N; i++) {
        cin>>x[i];
    }
    x[N]=X;
    sort(x,x+N+1);
    for (int i=0; i<N; i++) {
        dis[i]=x[i+1]-x[i];
    }
    int D=dis[0];
    for (int i=1; i<N; i++) {
        D=gcd(D,dis[i]);
    }
    cout<<D<<endl;
    return 0;
}

Measured memory_bytes: 1024
from functools import reduce
from operator import xor
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
if len(C)==1:
    k=list(C.keys())[0]
    print("YNeos"[k!=0::2])
elif len(C)==2:
    (k1,v1),(k2,v2)=C.most_common(2)
    print("YNeos"[not(v2*2==v1 and k1^k1^k2==0)::2])
else:
    print("YNeos"[not(len(C)==3 and reduce(xor, C.keys())==0 and len(set(C.values()))==1)::2])

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


int main(){
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    int num[110] = {0};
    for (int i = 0; i < N; i++)
    {
        num[d[i]]++; 
    }
    int ans = 0;
    for (int i = 0; i < 101; i++)
    {
        if(num[i]>0) ans++;;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
 
int a[3][3];
int n;
int b;

bool check(bool flag[3][3]) {
	int i, j;
	rep(i, 3) {
		rep(j, 3) if (!flag[i][j]) break;
		if (j == 3) return true;
	}
	rep(j, 3) {
		rep(i, 3) if (!flag[i][j]) break;
		if (i == 3) return true;
	}
	
	if (flag[0][0] && flag[1][1] && flag[2][2]) return true;
	if (flag[0][2] && flag[1][1] && flag[2][0]) return true;
	return false;
}
 
signed main() {
	int i, j, k;
	
	rep(i, 3) rep(j, 3) cin >> a[i][j];
	cin >> n;
	
	bool flag[3][3] = {false};
	rep(i, n) {
		cin >> b;
		rep(j, 3) rep(k, 3) if (a[j][k] == b) flag[j][k] = true;
	}
	
	if (check(flag)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn_bellmanford=2505;
vector<vll> G(maxn_bellmanford);
bool reachableFrom1[maxn_bellmanford];
void dfs(ll v){
  if(reachableFrom1[v]) return;
  reachableFrom1[v]=true;
  for(auto nv: G[v]){
    dfs(nv);
  }
}

vector<vll> rG(maxn_bellmanford);
bool reachableToN[maxn_bellmanford];
void rdfs(ll v){
  if(reachableToN[v]) return;
  reachableToN[v]=true;
  for(auto nv: rG[v]){
    rdfs(nv);
  }
}

ll n,m;
vector<tuple<ll,ll,ll>> es;
ll dist[maxn_bellmanford];
bool ok[maxn_bellmanford];

bool bellmanford(ll s){
  fill(dist,dist+n,INF);
  dist[s]=0;
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(chmin(dist[b],dist[a]+c)) update=true;
    }
    if(cnt>=n){
      return true; // has negative loop
    }
    cnt++;
  }
  return false;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll p; cin>>n>>m>>p;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--; c=-(c-p);
    es.emplace_back(a,b,c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i]=reachableToN[i]&&reachableFrom1[i];
  if(bellmanford(0)){
    cout<<"-1"<<endl;
  }else{
    ll ans=-dist[n-1];
    if(ans<0) ans=0;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int V[50] = {}; 
	for(int i = 0; i < N; i++) cin >> V[i]; 
	double c = 0.5; 
	double ans = 0; 
  sort(V, V+N, greater<int>());
	for(int i = 0; i < N; i++){
		ans += c * (double) V[i]; 
		if(i != N-2) c *= 0.5; 
	}
	cout.precision(15); 
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll n,k;
ll ans;
vector<vector<ll> > v(100000);
bool niko[100000];
void dfs(ll a){
    ll maki=v[a].size();
    niko[a]=true;
    if(a){
        for(ll i=k-2,j=1;j<maki;j++,i--){
            ans*=i;
            ans%=mod;
        }
    }else{
        for(ll i=k-1,j=0;j<maki;j++,i--){
            ans*=i;
            ans%=mod;
        }
    }
    for(ll i=0;i<maki;i++){
        if(niko[v[a][i]]==0){
            dfs(v[a][i]);
        }
    }
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    memset(niko,0,sizeof(niko));
    ans=k;
    ll a,b;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        a--;b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(0);
    cout << ((ans%mod)+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 8192
<?php

fscanf(STDIN, '%d %d %d', $A, $B, $C);

$ans = 0;
$remain = $B;
while($remain - $A >= 0){
    $remain -= $A;
    $ans++;
    if($ans >= $C){
        break;
    }
}

echo $ans.PHP_EOL;

Measured memory_bytes: 4604
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int sx,sy;
int gx,gy;
vvi tmp;
int main(){
	int n;
	while(cin>>n,n){
		map<ll,ll>in;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			in[b]+=a;
			in[c]-=a;
		}
		int sum=0;
		bool h=true;
		for(map<ll,ll>::iterator it=in.begin();it!=in.end();it++){
			sum+=it->second;
			//cout<<sum<<endl;
			if(sum>150){h=false;break;}
		}
		cout<<(h?"OK":"NG")<<endl;
	}
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	ll i=1;
	while(i){
		if((ll)360*i%n==0){
			cout<<360*i/n<<'\n';
			break;
		}
		i++;
	}
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
	int X[128]={0};
	char c;
	for(;~(c=getchar());X[c]++);
	for(c=97;c<123;c++)
		printf("%c : %d\n",c,X[c]+X[c-32]);
	return 0;
}


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

long long n, a, b, t, t1, t2;
int main()
{
    cin >> n;
    while (n--) {
        scanf("%d %d", &t1, &t2);
        if (a <= t1 && b <= t2) {
            a = t1;
            b = t2;
        } else {
            t = max((t1 + a - 1) / t1, (t2 + b - 1) / t2);
            a = t * t1;
            b = t * t2;
        }
    }
    cout << a + b << endl;
    return 0;
}


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

using namespace std;

const int N = 2017;

char a[N], b[N];
char x[N];
pair<int, int > ve[N];

int main() {
  scanf("%s", a);
  scanf("%s", b);
  int n = strlen(a);
  int ans = 1e8;
  for (int sl = -n; sl <= n; sl++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      x[i] = a[(i+n-sl) % n];
      cnt += x[i] != b[i];
      ve[i] = make_pair(-1e8, 1e8);
    }
    if (cnt == 0)
      ans = min(ans, abs(sl));
    int last = -1;
    for (int i = 0; i < 3 * n; i++) {
      if (b[i % n] == '1')
        last = i;
      if (x[i % n] != b[i % n]) {
        if (last == -1) continue;
        ve[i % n].first = max(min(last - i + sl, 0), ve[i % n].first);
      }
    }

    last = -1;
    for (int i = 3 * n; i >= 0; i--) {
      if (b[i % n] == '1')
        last = i;
      if (x[i % n] != b[i % n]) {
        if (last == -1) continue;
        ve[i % n].second = min(max(last - i + sl, 0), ve[i % n].second);
      }
    }
    vector<pair<int, int > > vv;
    for (int i = 0; i < n; i++) if (b[i] != x[i])
      vv.push_back(ve[i]);
    sort(vv.begin(), vv.end());
    int ri = max(0, sl);
    for (int le = -n, j = 0; le <= min(sl, 0); le++) {
      while (j < vv.size() && vv[j].first < le) ri = max(ri, vv[j].second), j++;
      ans = min(ans, cnt + ri-le + ri - le -abs(sl));
    }
  }
  if (ans >= 1e8)
    ans = -1;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int A, B, tmp, r;
  cin >> A >> B;
  long int a=A;
  long int b=B;
  if(A<B){
    tmp = A;
    A = B;
    B = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = A % B;
  while(r!=0){
    A = B;
    B = r;
    r = A % B;
  }
  r=a*b/B;
  cout << r << endl;
  
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int h, m, s;
    s = scan.nextInt();
    m = s % 3600 / 60;
    h = s / 3600;
    s = s % 60;
    System.out.println(h + ":" + m + ":" + s);
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int on = 1;
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int counter = 0;
    while(counter <= N){
        if(counter == N){
            cout << "-1" << endl;
            break;
        }
        if(on == 2){
            cout << counter << endl;
            break;
        }
        on = a.at(on - 1);
        counter++;
    }

}


Measured memory_bytes: 640
N = int(input())
a = [int(input()) for i in range(N)]

lmax = [0]
rmax = [0]

for i in range(N-1):
    lmax.append(max(lmax[i], a[i]))
    rmax.append(max(rmax[i], a[-(i+1)]))

for i in range(N):
    print(max(lmax[i], rmax[-(i+1)]))

Measured memory_bytes: 15676
#include <stdio.h>

int main(){

  int i, n;
  int a[100];

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for(i = n-1; i >= 0; i--){
    if( i != n - 1 )
      printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

// int MOD = 998244353;
int MOD = 1000000007;


signed main(){
	
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	vector<ll> c(n);

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

	int cnt[30] = {0};
	rep(bit,29){
		rep(i,n)c[i] = b[i]%(1LL<<(1+bit));
		SORT(c);
		rep(ai,n){
			ll fa = a[ai]%(1LL<<(1+bit));
			ll x = 1LL<<bit;
			auto r1 = lower_bound(c.begin(),c.end(),x-fa);
			auto r2 = lower_bound(c.begin(),c.end(),2*x-fa);
			auto r3 = lower_bound(c.begin(),c.end(),x+2*x-fa);
			auto r4 = lower_bound(c.begin(),c.end(),4*x-fa);
			cnt[bit] += (ll)(r2-r1) + (ll)(r4-r3); 
		}
	}

	ll ans = 0;
	rep(i,29){
		ans += (1LL<<i)*(cnt[i]%2);
	}

	cout << ans << endl;


	return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_a
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://arc092.contest.atcoder.jp/tasks/arc092_b

Measured memory_bytes: 4992
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = 0;
    
    for(int i=a ; i<=b ; i++){
      int a1 = i/1000;
      int a11 = a1/10;
      int a12 = a1%10;
      
      int b1 = (i%1000)%100;
      int b11 = b1/10;
      int b12 = b1%10;
      
      if( (a11==b12) && (a12==b11) ){
        sum++;
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<pair<string,int>> v(n);
  for(auto& x: v){
    cin >> x.first >> x.second;
  }
  string key;cin >> key;

  int flag=0,s=0;
  rep(i,n){
    if(flag) s+=v.at(i).second;
    if(v.at(i).first==key) flag=1;
  }
  cout << s;
}

/// confirm df==0 ///


Measured memory_bytes: 256
A,B = map(int,input().split())
grid = [[0]*50+[1]*50 for _ in range(100)]
point = 0
for a in range(A-1):
    grid[point%100][int(point/100)*2] = 1
    point += 2
point = 0
for b in range(B-1):
    grid[point%100][99-int(point/100)*2] = 0
    point  += 2
print(100,100)
for gg in grid:
    temp = ""
    for g in gg:
        temp += "#" if g == 0 else "."
    print(temp)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] L = new int[N];
		for(int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		sc.close();
		
		int count = 1;
		int distance = 0;
		for(int i = 0; i < N; i++) {
			distance += L[i];
			if(distance <= X) {
				count++;
				continue;
			}else {
				break;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22996
#include <iostream>
using namespace std;
constexpr int S_max = 1'000'000'000;
int main() {
    int n, k, s;
    cin >> n >> k >> s;

    int i = 0;
    for (; i < k; i++)
        printf("%d%c", s, (i == n - 1 ? '\n' : ' '));
    for (; i < n; i++)
        printf("%d%c", (s < S_max ? S_max : 1), (i == n - 1 ? '\n' : ' '));
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>

long long int dp[2][10];
int n, m, nums[10];
char id[100005];

int main(){
  dp[1][0] = 1;
  scanf("%d", &n);
  scanf("%s", id);
  scanf("%d", &m);
  for(int i = 0;i < m;i++){
    scanf("%d", nums + i);
  }
  for(int i = 0;i < n;i++){
    int twotime = 1;
    if((n - i) % 2 == 0){
      twotime = 2;
    }
    if(id[i] == '*'){
      for(int j = 0;j < 10;j++){
dp[i % 2][j] = 0;
for(int k = 0;k < m;k++){
int add = (nums[k] * twotime) % 10 + (nums[k] * twotime) / 10;
dp[i % 2][j] += dp[1 - (i % 2)][(j + 10 - add) % 10];
}
      }
    }
    else{
      int k = id[i] - '0';
      for(int j = 0;j < 10;j++){
dp[i % 2][j] = 0;
int add = (k * twotime) % 10 + (k * twotime) / 10;
dp[i % 2][j] += dp[1 - i % 2][(j + 10 - add) % 10];
      }
    }
  }
  printf("%lld\n", dp[(n - 1) % 2][0]);
}

Measured memory_bytes: 1128
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,m = get_nums_l()
qqq = list(map(lambda s: s.strip().split(), sys.stdin.readlines()))
qqq = list(map(lambda q: (int(q[0]), q[1]), qqq))
qqq.sort(key=lambda q: q[0])

prev = None
wa = 0
accepted = set()
ans_wa = 0
for q in qqq:
    no = q[0]
    ju = q[1]
    if no != prev:
        wa = 0
    if ju == "AC":
        if no not in accepted:
            accepted.add(no)
            ans_wa += wa
    if ju == "WA":
        wa += 1
    prev = no

print(len(accepted), ans_wa)

Measured memory_bytes: 91740
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
   queue<int> q;
   q.push(s);
   for ( int i = 0; i < n; i++) d[i] = INFTY;
   d[s] = 0;
   int u;

   while ( !q.empty() ) {
      u = q.front(); q.pop();
      for ( int v = 0; v < n; v++ ) {
         if ( M[u][v] == 0 ) continue;
         if ( d[v] != INFTY ) continue;
         d[v] = d[u] + 1;
         q.push(v);
      }
   }

   for ( int i = 0; i < n; i++ ) {
      cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
   }
}

int main() {
   int u, k, v;

   cin >> n;
   for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) M[i][j] = 0;
   }

   for ( int i = 0; i < n; i++ ) {
      cin >> u >> k;
      u--;

      for (int j = 0; j < k; j++ ) {
         cin >> v;
         v--;
         M[u][v] = 1;
      }
   }

   bfs(0);

   return 0;
}

Measured memory_bytes: 3140
// JOOI 2009 予選 3

#include <cstdio>
#include <iostream>
#include <deque>

using namespace std;



int main(void)
{
	int N,M;

	while(	cin >> N >> M, N && M){

		int d[501] = {};
		bool ans[501] = {};
		deque<int> ffrend[501]= {};


	int a,b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;

		ffrend[a].push_back(b);
		ffrend[b].push_back(a);

	}
	
	
	while(ffrend[1].size()){

		int f = ffrend[1].front();	//自分の友達の番号
		ans[f] = true;				//自分の友達

		while(ffrend[f].size()){

			int ff = ffrend[f].front();	//友達の友達


			ans[ff] = true;				//友達の友達
			ffrend[f].pop_front();
		}
		if(ffrend[1].size())
			ffrend[1].pop_front();
	}

	int count = 0;

	for(int i = 2; i <= N; i++)
		if(ans[i])
			count++;

	cout << count << endl;

	}

	return 0;
}


//  （´・ω・｀）

Measured memory_bytes: 1532
#include<iostream>
#include<cmath>
#include<tuple>
#include<algorithm> // sort,reverse
using namespace std;
#define df 0
long int norm(long int x,long int y){
  return x*x+y*y;
}

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >> n;
  tuple<double,int,int> engs[2*n];
  for(int i=0;i<n;i++){
    int x,y;
    cin >> x >> y;
    get<0>(engs[i])=atan2(x,y);
    get<1>(engs[i])=x;
    get<2>(engs[i])=y;
  }
  sort(engs,engs+n);
  for(int i=0;i<n;i++){
    engs[i+n]=engs[i];
  }
  if(df){
    for(int i=0;i<2*n;i++){
      printf("%lf,%d,%d\n",get<0>(engs[i]),get<1>(engs[i]),get<2>(engs[i]));
    }
  }
  long int max_d=0;
  for(int i=0;i<n;i++){
    long int x=0,y=0;
    for(int j=0;j<n;j++){
      x+=get<1>(engs[i+j]);
      y+=get<2>(engs[i+j]);
      long int temp=norm(x,y);
      if(max_d<temp){
	max_d=temp;
	if(df)printf("%d %d %ld\n",x,y,max_d);
      }
    }
  }
  printf("%.15lf",sqrt(max_d));
}

/// confirm df==0 ///

Measured memory_bytes: 256
from bisect import bisect_left


def p_d():
    N = int(input())
    L = list(map(int, input().split()))

    ans = N * (N - 1) * (N - 2) // 6
    L.sort()

    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            b = bisect_left(L, L[i] + L[j])
            if b != N:
                ans -= N - b

    print(ans)


if __name__ == '__main__':
    p_d()


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

int n,a,b,c,d,q,k;

bool good(int x)
{
    int nrb = b-max(0,(x-1)/k);
    if (nrb<=1LL*(a-x+1)*k)
        return true;
    return false;
}

int main()
{
    cin>>q;
    for (int i=1;i<=q;i++)
    {
        cin>>a>>b>>c>>d;

        int ma = max(a,b);
        int mb = min(a,b);
        k = ma/(mb+1)+(ma%(mb+1)!=0);
        int p = 1,st = 0;
        for (;p<=a;p<<=1);
        for (;p>=1;p>>=1)
            if (st+p<=a && good(st+p))
                st+=p;

        int x = max(0,(st-1)/k)+st;
        if (c<=x)
            for (int i=c;i<=min(d,x);i++)
            {
                if (i%(k+1)==0) cout<<'B';
                else cout<<'A';
            }
        a += b;
        if (d>x)
            for (int i=max(x+1,c);i<=d;i++)
            {
                if ((a-i+1)%(k+1)==0) cout<<'A';
                else cout<<'B';
            }
        cout<<'\n';
    }

    return 0;
}


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

ll gcd(ll a, ll b){
  if(a%b==0LL) return b;
  return gcd(b, a%b);
}

int main(){
  ll n, m; cin >> n >> m;
  string s, t;  cin>> s >> t;
  ll g = gcd(n, m);
  ll ans= n/g*m;

  if(s!=t && n==m) ans = -1;
  else{
    n /= g; m /= g;
    for(ll i=0; i<g; i++){
      if(s[i*n]==t[i*m]) continue;
      ans = -1;
    }
  }

    cout << ans << endl;

  
  
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
const int maxn=1e5+7;
int n,a,b;
int H[maxn];
bool judge(LL mid)
{
    LL mul=mid*b;
    LL sum=0;
    for(int i=n;i>=1;i--)
    {
        if(H[i]>mul)
        {
            if((H[i]-mul)%(a-b))
                sum+=(H[i]-mul)/(a-b)+1;
            else
                sum+=(H[i]-mul)/(a-b);
        }
    }
    return sum<=mid;
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    LL r=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&H[i]);
        r+=H[i]/b+1;
    }
    sort(H+1,H+n+1);
    LL l=1;
    while(l<r)
    {
        LL mid=(l+r)>>1;
        if(judge(mid))
            r=mid;
        else
            l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
    int i, n, arr[100];
    const char *fmt = "%d";
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", arr+i);
    }
    for (i = n-1; i >= 0; i--) {
        printf(fmt, arr[i]);
        fmt = " %d";
    }
    putchar('\n');
    return 0;
}



Measured memory_bytes: 2104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 300000


int main(){
	int a[N+1];
	f(i, N+1)a[i] = 0;
	int n, k;
	int x;
	long long m;
	bool v = true;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		if (i > 0){
			if ((m + 1) < x)v = false;
		}
		k = i - x;
		if (k < 0)v = false;
		else a[k] = x;
		m = x;
	}
	m = 0;
	for (int i = 0; i <= n; i++){
		m += a[i];
	}

	if(v)printf("%lld\n", m);
	else printf("-1\n");


	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define P(x,y) (s[x][y]=='#')
const int M=1e9+7;
long long n,m,r,tr,td,sr,sd,tt,k,z,a;string s[1001];
int mi(int a,long long b){int s=1;
	for(;b;b>>=1,a=1LL*a*a%M)if(b&1)s=1LL*s*a%M;
	return s;
}
int main(){
	cin>>n>>m>>k;
	ref(i,1,n){cin>>s[i],s[i]=" "+s[i];ref(j,1,m)tt+=P(i,j);}
	ref(i,1,n){tr+=(P(i,1)&&P(i,m));ref(j,2,m)sr+=(P(i,j)&&P(i,j-1));}
	ref(i,1,m){td+=(P(1,i)&&P(n,i));ref(j,2,n)sd+=(P(j,i)&&P(j-1,i));}
	if(tr&&td||k<2)r=1;else{
		r=mi(tt,k-1);
		if(td)tr=td,sr=sd;
		if(tr){
			z=1LL*tr*mi(tt,M-2)%M;
			r=(M+r-sr*mi(tt,k-2)%M*(mi(z,k-1)-1)%M*mi(z-1,M-2)%M)%M;
		}
	}
	cout<<r<<endl;
}

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

int main() {
    string s; cin >> s;
    int ans = 1e9;
    for (int i = 0; i < s.size() - 2; ++i) {
        int num = stoi(s.substr(i, 3));
        ans = min(ans, abs(753 - num));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int N;
void Qt(int l,int r){
  cout << "?" << " ";
  if(r>l)rep(i,l,r)cout << i << " ";
  else{
    rep(i,l,2*N+1)cout << i << " ";
    rep(i,1,r)cout << i << " ";
  }
}
int main(){
  lli C,D,E,F,/*N,*/M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,char,2*N,'.');
  Vec(Q,char,2*N,'.');
  R=N+1;
  L=1;
  Qt(L,L+N);
  Out("");
  cin >> S;
  P[0]=S[0];
  Qt(R,R+N);
  Out("");
  cin >> S;
  P[N]=S[0];
  while(R-L>1){
    M=(R+L)/2;
    Qt(M,M+N);
    Out("");
    cin >> S;
    P[M-1]=S[0];
    if(P[L-1]==P[M-1])L=M;
    else R=M;
  }
  Q[L-1]=P[L-1];
  Q[L+N-1]=P[L+N-1];
  rep(i,1,2*N+1){
    if(Q[i-1]!='.')continue;
    if(i<L||i>L+N){
      Qt(L+1,L+N);
      Out(i);
      cin >> S;
      Q[i-1]=S[0];
    }
    else{
      Qt(L+N+1,L);
      Out(i);
      cin >> S;
      Q[i-1]=S[0];
    }
  }
  cout << "!" << " ";
  rep(i,0,2*N)NeOut(Q[i]);
  Out("");
}

Measured memory_bytes: 724
#include <iostream>

using namespace std;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    if ((a == b && b == c) || (a != b && a != c && b != c)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> v(4, 0);
  for(int i = 0; i < 6; i++){
    int x;
    cin >> x;
    v[x-1]++;
  }
  sort(v.begin(), v.end());
  if(v[0] == 1 && v[1] == 1 && v[2] == 2 && v[3] == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int sum = 0;
  for (int i = 0; i < M; i++)
  {
    cin >> A[i];
    sum += A[i];
  }
  if (sum <= N)
  {
    cout << N - sum << endl;
  }
  else
  {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3668
# AOJ ITP2_8_D: Multi-Map
# Python3 2018.6.24 bal4u

import bisect
from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = []
			insort_left(keytbl, ki)
		dict[ki].append(int(a[2]))
	elif a[0] == '1' and ki in dict and dict[ki] != []: print(*dict[ki], sep='\n')
	elif a[0] == '2' and ki in dict: dict[ki] = []
	elif a[0] == '3':
		L = bisect_left (keytbl, a[1])
		R = bisect_right(keytbl, a[2])
		for j in range(L, R):
			for k in dict[keytbl[j]]:
				print(keytbl[j], k)


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

using namespace std;

map <int,int> d;

int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	
	cin >> s;
	
	cout << s.substr(0,s.length() - 8) << '\n';
	
	return 0;
}

Measured memory_bytes: 256