akhauriyash/Code-Regression huggingface dataset:
#
# abc165 c
#
import sys
from io import StringIO
import unittest
sys.setrecursionlimit(100000)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 4 3
1 3 3 100
1 2 2 10
2 3 2 10"""
        output = """110"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328"""
        output = """357500"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 10 1
1 10 9 1"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    global N, M, ABCD
    N, M, Q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for _ in range(Q)]

    print(dfs([1]))


def dfs(L):
    if len(L) == N:
        score = 0
        for abcd in ABCD:
            a, b, c, d = abcd
            if L[b-1] - L[a-1] == c:
                score += d
        return score

    ans = 0
    for i in range(L[-1], M+1):
        NL = L + [i]
        ans = max(ans, dfs(NL))

    return ans


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

#define ll long long

int main() {
    int A;
    int B;
    string s;
    cin >> s;

    A = (s[0] - 48)*10 + (s[1] - 48);
    B = (s[2] - 48)*10 + (s[3] - 48);

    if(0 < A && A <= 12 && (B == 0 || 12 < B)) {
        cout << "MMYY" << endl;
    }else if((A == 0 || 12 < A) && 0 < B && B <= 12) {
        cout << "YYMM" << endl;
    }else if(0 < A && A <= 12 && 0 < B && B <= 12) {
        cout << "AMBIGUOUS" << endl;
    }else{
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[1000010],g;
vector<int> p;
int cnt[1000010];
bool isprime(int x){
	int s=sqrt(x);
	for(int i=2;i<=s;i++)
		if(x%i==0)
			return 0;
	return 1;
}
int main(){
	for(int i=2;i<=1000;i++)
		if(isprime(i))
			p.push_back(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i==1)
			g=a[i];
		else
			g=__gcd(g,a[i]);
	}
	if(g>1){
		printf("not coprime\n");
		return 0;
	}
	for(int i=1;i<=n;i++){
		int x=a[i];
		int s=sqrt(x);
		for(int j=0;p[j]<=s&&j<p.size();j++){
			if(x%p[j]==0){
				cnt[p[j]]++;
				if(cnt[p[j]]>1){
					printf("setwise coprime\n");
					return 0;
				}
				while(x%p[j]==0)
					x/=p[j];
			}
		}
		if(x>1)
			cnt[x]++;
		if(cnt[x]>1){
			printf("setwise coprime\n");
			return 0;
		}
	}
	printf("pairwise coprime\n");
	return 0;
}

Measured memory_bytes: 7904
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int a,b;
 cin>>a>>b;
 int s;
 s = b-a;
 for(int i = 1; i <= 999; i++){
     int B;
     if(i%2 ==0){
         B = (1 + i)*i/2;
     }
     else {
         B = (1+i)*(i-1)/2+((i-1))/2+1;
     }
     int S;
     S = B-(B-i);
         if(S == s){
           cout<<B-b<<endl;
         }
     
 }
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string ans = s.Substring(2, 1).Equals(s.Substring(3, 1)) && s.Substring(4, 1).Equals(s.Substring(5, 1)) ? "Yes" : "No";
        Console.WriteLine(ans);
    }


  

}



Measured memory_bytes: 13140
#include <iostream>
using namespace std;
char a[3][3];
char b[3];
int main()
{
	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			cin>>a[i][j];
			if (i==0 && j==0)
				b[0]=a[i][j];
			if (i==1 && j==1)
				b[1]=a[i][j];
			if (i==2 && j==2)
				b[2]=a[i][j];
		}
	}
	for (int i=0;i<3;i++)
	{
		cout<<b[i];
	}
	//system("pause");
    return 0;
}

Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 


bool isTri(ll a, ll b, ll c) {
	set<ll>st;
	st.insert(a);
	st.insert(c);
	st.insert(b);
	return st.size() == 3 and (a + b > c) and (b + c > a) and (c + a > b);
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	std::vector<ll> v;
	cin >> n;

	rep(i, 0, n, 1) {
		cin >> x;
		v.push_back(x);
	}

	z = 0;

	sort(all(v));
	debug(v);


#define tup pair<ll,pll>
// #define tup tuple<ll,ll,ll>
	set<tup> s;


	rep(i, 0, n, 1) {
		rep(j, i + 1, n, 1) {
			rep(k, j + 1, n, 1) {
				if (isTri(v[i], v[j], v[k])) {
					// s.insert(make_pair(v[i], make_pair( v[j], v[k])));
					z++;
					// s.insert(make_tuple(v[i], v[j], v[k]));
				}

			}
		}
	}


	debug(s);
	z += s.size();
	ce(z);
	debug(z);
}



Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
    int n;
    int b;
    int f;
    int r;
    int v;
    int a[4][3][10] = {0};
    
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        a[b - 1][f - 1][r - 1] += v;
    }
    
    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 3; j++ ) {
            for ( int k = 0; k < 10; k++ ) {
                printf(" %d", a[i][j][k]);
            }
            printf("\n");
        }
        if ( i != 3 ) {
            printf("####################\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2084
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
int main()
{
	char c[26] = {};
	char s[100001]; cin >> s;
	ll i = 0;
	while (s[i]) {
		c[s[i] - 'a']++;
		i++;
	}
	rep(i, 0, 26) {
		if (!c[i]) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int n;
  cin >> n;
  int ans = (n / 11) * 2;
  n %= 11;
  if(n > 6) ans++;
  if(n) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if (s.size() == 2) {
	cout << s << endl;
  }
  else {
	reverse(s.begin(), s.end());
	cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 256
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
ll tt[14][14];
ll mat[14][14];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,i,j,k,is=1e17,x,val;
    cin>>n>>m>>k;
    for(i=0;i<n;++i){
    	for(j=0;j<m+1;++j){
    		cin>>tt[i][j];
    		mat[i][j]=tt[i][j];
		}
	}
	for(i=1;i<n;++i){
		for(j=0;j<m+1;++j){
			tt[i][j]+=tt[i-1][j];
		}
	}
	int f=1;
	for(j=1;j<m+1;++j){
		if(tt[n-1][j]<k){
			f=0;
			break;
		}
	}
	if(f==0){
		cout<<"-1";
		return 0;
	}
	ll  count = pow(2,n);
	// The outer for loop will run 2^n times to print all subset .
	// Here variable i will act as a binary counter
	for (i = 0; i < count; i++)
	{
		// The inner for loop will run n times , As the maximum number of elements a set can have is n
		// This loop will generate a subset
		vll v;
		for (j = 0; j < n; j++)
		{
			// This if condition will check if jth bit in binary representation of  i  is set or not
			// if the value of (i & (1 << j)) is greater than 0 , include arr[j] in the current subset
			// otherwise exclude arr[j]
			if ((i & (1 << j)) > 0)
			{
				v.pb(j);
			}
		}
		ll su[14];
		for(j=0;j<=13;++j){
			su[j]=0;
		}
		for(x=0;x<(ll)v.size();++x){
			for(j=1;j<m+1;++j){
				su[j]+=mat[v[x]][j];
			}
		}
		int f=1;
		for(j=1;j<m+1;++j){
			if(su[j]<k){
				f=0;
				break;
			}
		}
		if(f){
			ll co=0;
			for(j=0;j<(ll)v.size();++j){
				co+=mat[v[j]][0];
			}
			is=min(is,co);
		}
	}
	cout<<is;
}

Measured memory_bytes: 4068
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int N,d[200],a[100],c;
int main(){

	cin>>N;
	for(int i=0;i<N;i++){
		cin>>d[i];
		a[d[i]]++;
		if(a[d[i]]>=2){
			c++;
		}
	}
	cout<<N-c<<endl;;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define swap(a,b) {a+=b;b=a-b;a-=b;}
#define ll long long

using namespace std;

main(){
  int N;
  scanf("%d",&N);
  int A[N];
  ll B[N+1]={};
  rep(i,0,N){
    scanf("%d",&A[i]);
    B[A[i]]++;
  }
  ll ans=0;
  rep(i,0,N+1)ans+=B[i]*(B[i]-1)/2;
  rep(i,0,N){
    printf("%lld",ans-(B[A[i]]-1));
    if(i<N-1)printf("\n");
  }
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<string.h>
int main()
{
	char a[10],b[10],c[10];
	int len,lon,lan;
	
	scanf("%s %s %s",a,b,c);
	
	len=strlen(a);
	lon=strlen(b);
	lan=strlen(c);
	
	if(a[len-1]==b[0] && b[lon-1]==c[0]){
            
		printf("YES\n");
	}
	else{
		printf("NO\n");
    
	}
	return 0;
}


Measured memory_bytes: 128
<?php

for($i=0; $i<5; $i++){
  $s[$i] = trim(fgets(STDIN));
}

$ans = 'Yay!';
$k = trim(fgets(STDIN));
for($i=0; $i<4; $i++){
  for($j=$i; $j<5; $j++){
    $n = abs($s[$i]-$s[$j]);
    if ($n > $k) {
      $ans = ':(';
      break;
    }
  }
}

echo $ans;

?>

Measured memory_bytes: 4728
#include<stdio.h>
typedef struct{
  int value;
  char moji;
}card;

int main(){
  int i,j,n,miji;

  card num[36],suit[36],temp;
 
  scanf("%d",&n);
for(i=0;i<n;i++){
  scanf(" %c%d",&num[i].moji,&num[i].value);
  suit[i].moji = num[i].moji;
 suit[i].value = num[i].value;
  }
 for(i=0;i<n;i++){
   for(j = n-1;j>i;j--){
     if(num[j].value < num[j-1].value){
       temp = num[j];
       num[j] = num[j-1];
       num[j-1] = temp;
    }
   }
 }
for(i=0;i<n-1;i++){
   printf("%c%d ",num[i].moji,num[i].value);
 }
 printf("%c%d\nStable\n",num[i].moji,num[i].value);


 for(i=0;i<n-1;i++){
   miji = i;
   for(j=i;j<=n-1;j++){
     if(suit[j].value < suit[miji].value) miji = j;
   }
     temp = suit[i];
     suit[i]=suit[miji];
     suit[miji]=temp;


   


 }




 for(i=0;i<n-1;i++){
   printf("%c%d ",suit[i].moji,suit[i].value);
 }
 printf("%c%d\n",suit[i].moji,suit[i].value);

 for(i=0;i<n;i++){
   if(suit[i].moji != num[i].moji) {printf("Not stable\n"); break;}
 }
 if(i == n){printf("Stable\n");}
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N, A; cin >> N;
	vector<int> array;

	for (int i = 0; i < N; ++i) {
		cin >> A;
		array.push_back(A);
	}

	for (int i = 0; i < N; ++i)
		cout << array[i] << ((i == N - 1) ? "\n" : " ");

	for (int i = 1; i < N; ++i) {
		int v = array[i];
		int j = i - 1;
		while (j >= 0 and array[j] > v)
		{
			array[j + 1] = array[j];
			--j;
		}
		array[j + 1] = v;
		for (int i = 0; i < N; ++i)
			cout << array[i] << ((i == N - 1) ? "\n" : " ");
	}
}


Measured memory_bytes: 3140
let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

(* 配列版素集合データ構造 *)
module RawUnionFind : sig
  type t
  type class_

  (* n要素の素集合データ構造を作る *)
  val make : int -> t
  (* 要素がどの集合に属するか調べる *)
  (* 要素は0からn-1の整数である必要がある *)
  val find : t -> int -> class_
  (* 与えられた要素が属する集合同士を合併する *)
  val unite : t -> int -> int -> unit

  val compare_class : class_ -> class_ -> int
end = struct
  type t = { rank : int array; parent : int array }
  type class_ = int

  let make n =
    { rank = Array.make n 0;
      parent = Array.init n (fun c -> c) }

  let rec find uf x =
    if x = uf.parent.(x) then x
    else begin
      let y = find uf uf.parent.(x) in
      uf.parent.(x) <- y; y
    end

  let unite uf i j =
    let x = find uf i in
    let y = find uf j in
    if x <> y then begin
      if uf.rank.(x) < uf.rank.(y) then uf.parent.(x) <- y
      else begin
        uf.parent.(y) <- x;
        if uf.rank.(x) = uf.rank.(y) then
          uf.rank.(x) <- 1 + uf.rank.(x)
      end
    end

  let compare_class = compare
end

module ClassMap = Map.Make (struct
  type t = RawUnionFind.class_
  let compare = RawUnionFind.compare_class
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let uf = RawUnionFind.make n in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ RawUnionFind.unite uf
  done;
  let m = Array.fold_left (fun m i ->
    ClassMap.add (RawUnionFind.find uf i)
      (as_.(i) :: try ClassMap.find (RawUnionFind.find uf i) m with Not_found -> []) m) ClassMap.empty @@
    Array.init n @@ fun i -> i in
  if n < (ClassMap.cardinal m - 1) * 2 then print_endline "Impossible"
  else if ClassMap.cardinal m = 1 then print_endline "0"
  else
    ClassMap.fold (fun _ (a :: as_) (acc, rest) ->
      let (a, acc, rest) =
        List.fold_left (fun (a, acc, rest) a' ->
          if a <= a'
          then (a, acc, a' :: rest)
          else (a', acc, a :: rest)) (a, acc, rest) as_ in
      (a + acc, rest)) m (0, [])
    |> fun (acc, rest) ->
        Printf.printf "%d\n" @@
          List.fold_left ( + ) acc @@
            take (ClassMap.cardinal m - 2) @@
              List.sort compare rest


Measured memory_bytes: 17024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll dp[100010];
vector<ll>v;
int main() {
	rep(i, 100010)dp[i] = INF;
	ll i = 1;
	v.pb(i);
	while (i < 1000000) {
		i *= 6;
		v.push_back(i);
	}
	i = 1;
	while (i < 1000000) {
		i *= 9;
		v.push_back(i);
	}
	sort(ALL(v));
	ll n;
	cin >> n;
	dp[0] = 0;
	rep(i, n) {
		rep(j, v.size()) {
			if (i + v[j] > n)break;
			dp[i + v[j]] = min(dp[i + v[j]], dp[i] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
using Ps=pair<int,string>;
int main(){
    int n;
    cin>>n;
    map<string,int>mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    vector<Ps>v;
    for(auto x:mp){
        v.push_back(Ps(x.sc,x.fs));
    }
    n=v.size();
    sort(all(v));
    int mx=v[n-1].fs;
    rep(i,n){
        if(v[i].fs==mx)cout<<v[i].sc<<endl;
    }
    return 0;
}

Measured memory_bytes: 29368
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    final int r = scanner.nextInt();

    if(n >= 10) {
      System.out.println(r);
    } else {
      System.out.println(r + 100 * (10-n));
    }

  }

}


Measured memory_bytes: 21716
N,K = gets.split.map(&:to_i)
A = gets.strip.split.map(&:to_i)
A.sort!
B = []
answer = 0
a = 0

for i in 0..N-2

    if A[i] != A[i+1]

        B.push(i-a+1)
        a = i+1

    end

end

B.push(N-a)
B.sort!

if B.size-K > 0

    for i in 0..B.size-K-1

        answer += B[i]

    end

end

puts answer 


Measured memory_bytes: 20332
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void push(int);

int pop(void);

int top,t[101];

int main()
{
  int x = 0,a = 0,b = 0,c = 0,d = 0,e = 0;
  char s[100];
  
  
  while( scanf("%s", s) != EOF )
    {
      if( s[0] == '+' )
	{
	  a = pop();
	  b = pop();
	  c = a+b;
	  push(c);
	}
      else if( s[0] == '-' )
	{
	  a = pop();
	  b = pop();
	  d = b-a;
	  push(d);
	} 
      else if( s[0] == '*' )
	{
	  a = pop();
	  b = pop();
	  e = a*b;
	  push(e);
	}
      else{
	x = atoi(s);
	push(x);
	}
    }
  printf("%d\n",pop());
  return 0;
}
void push(int x)
{
  top++;
  t[top] = x;
}
int pop(void)
{
  top--;
  return t[top+1];
}



Measured memory_bytes: 2104
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    string l;
    cin >> l;

    int n = l.size();
    mint doo = 1;
    mint ans = 0;
    rep(i, n) {
        if(l[i] == '1') {
            ans += doo * mint(3).pow(n-i-1);
            doo *= 2;
        } 
    }
    ans += doo;

    cout << ans << endl;
}

Measured memory_bytes: 512
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val ss = mutableMapOf<String, Int>()
    repeat(n) {
        val s = next()
        ss[s] = (ss[s] ?: 0) + 1
    }

    val m = nextInt()
    val tt = mutableMapOf<String, Int>()
    repeat(m) {
        val t = next()
        tt[t] = (tt[t] ?: 0) + 1
    }

    var max = 0
    ss.forEach(){
        val score = it.value - (tt[it.key] ?: 0)
        if (score > max) max = score
    }

    println(max)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31796
n,y = map(int, input().split())

y //= 1000
a,b,c = -1,-1,-1


fit = False
for ai in range(n+1):

    if ai*10> y or fit:
        break

    remain = n-ai
    for bi in range(remain+1):
        ci = remain - bi
        
        if y == ai *10  + bi * 5 + ci :
            a,b,c = ai,bi,ci
            fit = True

print('{} {} {}'.format(a,b,c))



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define Local
#ifdef Local
    #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
    void err() { std::cout << std::endl; }
    template<typename T, typename...Args>
    void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
    template <template<typename...> class T, typename t, typename... A> 
    void err(const T <t> &arg, const A&... args) {
    for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
    #define dbg(...)
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N = 1e5 + 10;

int main()
{
    fastIO;
    string s = "ACL";
    int k; cin >> k;
    while (k--) {
        cout << s;
    }    

    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	string S; cin>>S;
	set<char> dic;
	for(int i=0;i<S.size();i++){
		if(dic.count(S[i])){
			S="?";
			break;
		}
		else dic.insert(S[i]);
	}
	cout<<(S=="?" ? "no" : "yes")<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

// 最大公約数
long GreatestCommonDivisor(long a, long b) {
	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		long tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	/* 最大公約数を出力 */
	return b;
}

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

	//
	int N, X;
	cin >> N >> X;

	vector<int> vx(N, 0);
	rep(i, N) cin >> vx[i];

	vector<int> vx2 = vx;
	rep(i, N) vx2[i] = abs(vx2[i] - X);

	if (N >= 2) {
		int GCD = GreatestCommonDivisor(vx2[0], vx2[1]);
		if (N >= 3) {
			for (int i = 2; i != N - 1; ++i) {
				GCD = GreatestCommonDivisor(vx2[i], GCD);
			}
		}
		cout << GCD << endl;
	}
	else if (N == 1) {
		cout << vx2[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

s=input()
r=input()
n=len(s)-1;cnt=0
for i in range(n):
    if r[i]!=s[i]:
        cnt+=1
print(cnt)

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

int main() {
  // Failed to predict input format
  int n; cin>>n;
  vector<vector<int>> x(n);
  vector<vector<int>> y(n);
  rep(i,n){
    int ai; cin>>ai;
    rep(j,ai){
      int x_, y_; cin>>x_>>y_; x_--;
      x[i].push_back(x_);
      y[i].push_back(y_);
    }
  }

  ll ret = 0;
  for(int state=1; state < (1<<n); state++){
    bool ok = true;
    for(int i=0;i<n;++i){
      if( ! ((state>>i)&1) ) continue;   // i が正直者でない → 矛盾は発生し得ない
      for(int j=0;j<x[i].size();++j){
        if( (y[i][j]) ^ ((state>>x[i][j])&1) ) { ok = false; }
      }
      //if(!ok) break;
    }
    if(ok){
      ll num = __builtin_popcount(state);
      ret = max(num, ret);
    }
  }
  cout << ret << endl;
  return 0;
}


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


Measured memory_bytes: 9208
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))


Measured memory_bytes: 24752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int sumOfEachDegit(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  int N;
  cin >> N;
  
  int sum = sumOfEachDegit(N);
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
package main
     
    import (
            "fmt"
    )
     
    func main() {
            var n int
            fmt.Scan(&n)
     
            mincnt := n
            for i := 0; i <= n; i++ {
                    cnt := 0
                    nn := i
                    for nn > 0 {
                            cnt += nn % 6
                            nn /= 6
                    }
                    nn = n - i
                    for nn > 0 {
                            cnt += nn % 9
                            nn /= 9
                    }
                    if cnt < mincnt {
                            mincnt = cnt
                    }
            }
            fmt.Println(mincnt)
    }

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

signed main(){
	int H,W; cin>>H>>W;
	int ans=0;
	if(H==1 or W==1)ans=1;
	else if(H%2==0 or W%2==0)ans=H*W/2;
	else ans=(H*W+1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <limits>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)
// For debug
#ifdef _DEBUG
#define DD(x) cerr << #x << ":" << x << endl;
#define DDA(ary) \
cerr << #ary << ":" << endl;\
for (auto v : ary) { cerr << v << ","; }\
cerr << endl;
#else
#define DD(x)
#define DDA(ary)
#endif

const int MAX_N = 100005;
const int MAX_P = 1000005;
const int INF = 2 * MAX_P;
int n, k;

struct Node {
	vector<int> adjs;
	int low = -INF; // close range [low, high]
	int high = INF;
};
Node nodes[MAX_N];

// return: 条件を満たせるか？
bool dfs(int rootI, int parentI) {
	auto& rootNode = nodes[rootI];
	for (int childI : rootNode.adjs) {
		if (childI == parentI) continue;
		bool childCond = dfs(childI, rootI);
		if (childCond == false) 
			return false;
		if (nodes[childI].low == -INF || nodes[childI].high == INF) continue;

		int newLow = nodes[childI].low - 1;
		int newHigh = nodes[childI].high + 1;
		if (rootNode.low == -INF && rootNode.high == INF) {
			rootNode.low = newLow; rootNode.high = newHigh;
		}
		else {
			bool ismod2 =
				((rootNode.low - newLow) % 2 == 0) &&
				((rootNode.high - newHigh) % 2 == 0);
			if (ismod2 == false) 
				return false;
			rootNode.low = max(rootNode.low, newLow);
			rootNode.high = min(rootNode.high, newHigh);
			if (rootNode.high < rootNode.low) 
				return false;
		}
	}

	return true;
}
void decideTree(int rootI, int parentI) {
	if (parentI == -1) {
		nodes[rootI].high = nodes[rootI].low;
	}
	else {
		int parentV = nodes[parentI].low;
		int l = parentV - 1;
		int h = parentV + 1;
		if (nodes[rootI].low <= l && l <= nodes[rootI].high) {
			nodes[rootI].low = nodes[rootI].high = l;
		}
		else {
			nodes[rootI].low = nodes[rootI].high = h;
		}
	}
	for (int childI : nodes[rootI].adjs) {
		if (childI == parentI) continue;
		decideTree(childI, rootI);
	}
}
#include <cassert>

int main() {
	cin >> n;
	REPCLS(i, n - 1) {
		int a, b; cin >> a >> b;
		nodes[a].adjs.push_back(b);
		nodes[b].adjs.push_back(a);
	}
	cin >> k;
	REP(i, k) {
		int ix, p;
		cin >> ix >> p;
		nodes[ix].high = nodes[ix].low = p;
	}
	bool cond = dfs(1, -1);
	if (cond) {
		cout << "Yes" << endl;
		decideTree(1, -1);
		REPCLS(i, n) {
			assert(nodes[i].low == nodes[i].high);
			cout << nodes[i].low << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
#define MAXN 100005
#define inf 1000000000001
using namespace std;

int main (){
	
	//freopen("t.txt","r",stdin);
	int n,W; 
	long long w[111],v[111],maxv=0;
	
	cin>>n>>W;
	
	for (int i=1;i<=n;i++) {
		cin>>w[i]>>v[i];
		maxv+= v[i];
	}
	long long dp[100001];
	
	for (int i=1;i<=maxv;i++) {
		dp[i]=inf;
	}
	
	
	for (int j=1;j<=n;j++ ){
		for (int i=maxv;i>=v[j];i--){
			
			dp[i]= min (dp[i], dp[i-v[j]] +w[j] );
		}
	}
	
	for (int i=maxv;i>=0;i--){
		if ( dp[i]<=W )
		{
			cout<<i<<endl;
			return 0;
		}
	}
	
	
	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<int> x(w, 0), y(h, 0);
	map<pair<int, int>, int> bomb;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		x[b]++;
		y[a]++;
		bomb[make_pair(b, a)]++;
	}
	int maxX = 0, maxY = 0;
	for (int i = 0; i < w; i++) {
		maxX = max(maxX, x[i]);
	}
	for (int i = 0; i < h; i++) {
		maxY = max(maxY, y[i]);
	}
	vector<int> maxXs, maxYs;
	for (int i = 0; i < w; i++) {
		if (x[i] == maxX) {
			maxXs.push_back(i);
		}
	}
	for (int i = 0; i < h; i++) {
		if (y[i] == maxY) {
			maxYs.push_back(i);
		}
	}
	for (int xx : maxXs) {
		for (int yy : maxYs) {
			if (!bomb.count(make_pair(xx, yy))) {
				cout << maxX + maxY << endl;
				return 0;
			}
		}
	}
	cout << maxX + maxY - 1 << endl;
	return 0;
}

Measured memory_bytes: 28556
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define inf 1000000007
//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    ll n,W;
    cin >> n >> W;
    vector<ll> w(n),v(n);
    vector<vector<ll>> dp(n);
    for(ll i=0;i<n;i++)
    {
        cin >> w[i] >> v[i]; 
        dp[i].resize(100001);
        //cout << "check 1 " << endl; 
        for(ll j=0;j<100001;j++)
        dp[i][j]=inf;
    }
    //cout << "check 1 " << endl; 
    for(ll i=0;i<100001;i++)
    {
        if(i<=v[0])
        {
            dp[0][i]=w[0];
        }
        else
        {
            break;
        }
    }
    //cout << "check 1 " << endl; 
    for(ll i=1;i<n;i++)
    {
        for(ll j=0;j<100001;j++)
        {
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            if(v[i]<j)
            {
                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
            }
            else{
                dp[i][j]=min(dp[i][j],w[i]);
            }
        }
    }
    //cout << "check 1 " << endl; 
    for(ll j=100000;j>=0;j--)
    {
        if(dp[n-1][j]<=W)
        {
            cout << j << endl;
            break;
        }
    }
    //cout << "check 1 " << endl; 
	
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> isAC(n);
    vector<int> pena(n);
    for (int i = 0; i < m; ++i) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (s == "AC") isAC[p] = true;
        else if (s == "WA" and !isAC[p]) pena[p]++;
    }
    int ac = 0;
    int wa = 0;
    for (int i = 0; i < n; ++i) {
        if (isAC[i]) {
            ac++;
            wa += pena[i];
        }
    }
    cout << ac << " " << wa << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

signed main()
{
    
    speed
    int a,b;cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
}

Measured memory_bytes: 256
from itertools import combinations as cmb
n, k = map(int, input().split())
A = list(map(int, input().split()))
highest = [A[0]] * n
for i in range(1, n):
  highest[i] = max(A[i], highest[i-1])

def cost_calc(pattern):
  cost = 0
  max_height_re = 0
  for num in pattern:
    cost += max(max_height_re, highest[num]) - A[num]
    max_height_re = max(max_height_re, highest[num]) + 1
  return cost

max_val = float("inf")
for pattern in cmb(range(n), k):
  max_val = min(max_val, cost_calc(pattern))
print(max_val)

Measured memory_bytes: 41324
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
vector<ll> v;

int main(void)
{
	vector<ll> v;
	int n, k;
	ll t[100000];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		if (i != 0) {
			v.push_back(t[i] - t[i - 1] - 1);
		}
	}
	sort(v.begin(), v.end());
	ll ans = n;
	for (int i = 0; i < n - k; i++) {
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];

int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++) {
		if(i%k==0) {
			puts("OK");
			return 0;
		}
	}
	puts("NG");
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a[120];
    for (int i = 0; i < N; i++) cin >> a[i];
    
    int res = 0;
    sort(a, a + N);  //sort in ascending order
    for (int i = 1; i < N; i++) res += a[i] - a[i-1];
    
    cout << res << endl;
    return 0;
}


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

int main() {
        int m1, m2;
        m1 = 1;
        m2 = 1;
        for (m1; m1 < 10; m1++) {
                for (m2; m2 < 10; m2++) {
                        cout << m1 << "x" << m2 << "=" << m1*m2 << endl;
                }
m2 = 1;
        }
        return 0;
}

Measured memory_bytes: 2980
#!/usr/bin/env python3

if __name__ == '__main__':
    n, l = list(map(int, input().split()))
    a = []
    for i in range(1, n+1):
        a.append(l + i - 1)

    ab = abs(sum(a))
    for i in a:
        if abs(ab) > abs(i):
            ab = i
    print(sum(a) - ab)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
char s[10005];
int p[2], n;
vector < int > d[2];
bitset < 30000 > inq;
bool check(int k) 
{
    queue < int > q, q2; q.push(0); inq.reset();
    for (int i = 0; i < d[k].size(); ++i, swap(q, q2))
        for (int u, v; !q.empty();)
		{
            u = q.front(); q.pop(); inq[u+10000] = 0;
            v = u + d[k][i];
            if (!inq[v+10000]) q2.push(v), inq[v+10000] = 1;
            v = u - d[k][i];
            if (!inq[v+10000]) q2.push(v), inq[v+10000] = 1;
        }
    for (; !q.empty(); q.pop())
        if (q.front() == p[k]) return true;
    return false;
}
int main() {
    scanf("%s", s);
    scanf("%d%d", &p[0], &p[1]);
    n = strlen(s);
    for (int fir = 1, m = 0, i = 0, t = 0; i < n; ++i) 
	{
        if (s[i] == 'F') ++m;
        if (s[i] == 'T' || i == n - 1) 
		{
            if (fir) p[0] -= m, m = fir = 0;
            if (m) d[t].push_back(m);
            m = 0, t ^= 1;
        }
    } puts(check(0) && check(1) ? "Yes" : "No");
    return 0;
}

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

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int f[110][10];
int p[110][11];

int main() {
  int n; cin>>n;
  rep(i, n) rep(j, 10) cin>>f[i][j];
  rep(i, n) rep(j, 11) cin>>p[i][j];

  int ans = -INF;

  REP(i, 1, 1<<10) {
    int ret = 0;
    rep(j, n) {
      int cnt = 0;
      rep(k, 10) if (i & (1<<k) and f[j][k]) ++cnt;
      ret += p[j][cnt];
    }
    ans = max(ans, ret);
  }
  print(ans);

  return 0;
}


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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    if N.__contains__(N[0]*3):
        print(YES)
        return
    elif N.__contains__(N[1]*3):
        print(YES)
        return
    else:
        print(NO)
        return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = str(next(tokens))  # type: str
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n; rd(n);
  auto m=new int[](n), d=new int[](n);
  auto v=new int[](n), s=new int[](n);
  foreach(i; 0..n) rd(m[i], d[i], v[i], s[i]);
  
  int f(int v){
    return (v-1)%360+1;
  }
  
  auto days=new int[](361);
  foreach(i; 0..n){
    int st=(m[i]-1)*30+d[i];
    int ed=st+v[i]-1;
    foreach(_; 0..3){
      foreach(x; 1..1500){
        if(x<st){
          chmax(days[f(x)], max(0, s[i]-(st-x)));
        }else if(st<=x && x<=ed){
          chmax(days[f(x)], s[i]);
        }else{// ed<x
          chmax(days[f(x)], max(0, s[i]-(x-ed)));
        }
      }
      st+=360; ed+=360;
    }
  }
  
  days[0]=100100100;
  writeln(reduce!(min)(days));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

void chmax(T1, T2)(ref T1 x, T2 y){
  if(x<y) x=y;
}

Measured memory_bytes: 2440
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int n;
int a[N], dp[N], last[N], store[N];

int32_t main()
{
	IOS;
	cin>>n;
	dp[0] = 1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		dp[i] = dp[i-1];
		if(a[i-1] != a[i])
			dp[i] += store[a[i]];
		dp[i] %= MOD;
		if(a[i] != a[i-1])
			store[a[i]] += dp[i-1];
		store[a[i]] %= MOD;
	}
	cout<<dp[n];
	return 0;
}

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

int main() {
	int df = 100000;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		df *= 1.05;
		if (df % 1000 != 0) {
			df /= 1000;
			df++;
			df *= 1000;
		}
	}
	cout << df << endl;
	return 0;
}

Measured memory_bytes: 3000
def solve():
    N, Y = map(int, input().split())

    for x in range(N + 1):
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())

Measured memory_bytes: 3060
program sandglass
  implicit none
  integer :: x, k, q, a(100000), tt(200000,2), ans(100000), i
  integer :: tlft, trit, alft, arit, t0, t1, s
  logical :: rev
  a = 0
  tt = 0
  ans = 0
  read(*,*) x
  read(*,*) k
  read(*,*) tt(1:k,1)
  read(*,*) q
  do i = 1, q
    read(*,*) tt(k+i,1), a(i)
    tt(k+i,2) = i
  end do
  call merge_sort(tt(1:k+q,1:2))
  tlft = 0
  trit = x
  alft = 0
  arit = x
  rev = .false.
  t0 = 0
  do i = 1, k+q
    t1 = tt(i,1)
    s = tt(i,2)
    alft = alft-(t1-t0)
    if (alft.lt.0) then
      tlft = tlft-alft
      if (tlft.gt.x) tlft = x
      alft = 0
    end if
    arit = arit-(t1-t0)
    if (arit.lt.0) then
      trit = trit+arit
      if (trit.lt.0) trit = 0
      arit = 0
    end if
    if (tlft.ge.trit) then
      if (rev) then
        tlft = trit-1
        if (tlft.lt.0) tlft = 0
      else
        trit = tlft+1
        if (trit.gt.x) trit = x
      end if
    end if
    !write(*,'(6(i0,x))') t0, t1, tlft, trit, alft, arit
    t0 = t1
    if (s.eq.0) then
      rev = .not.rev
      alft = x-alft
      arit = x-arit
      cycle
    end if
    if (a(s).le.tlft) then
      ans(s) = alft
    else if (a(s).ge.trit) then
      ans(s) = arit
    else
      ans(s) = a(s)-tlft+alft
      if (rev) ans(s) = -a(s)+tlft+alft
    end if
    if (rev) ans(s) = x-ans(s)
  end do
  do i = 1, q
    write(*,'(i0)') ans(i)
  end do
  stop
contains
  subroutine merge_sort(c)
    implicit none
    integer, intent(inout) :: c(:,:)
    integer :: n, m, l, u, i
    n = size(c(:,1))
    m = n
    l = 1
    do while (m.gt.1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(c(2*(i-1)*l+1:(2*i-1)*l,:),c((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merger(c1,c2)
    implicit none
    integer, intent(inout) :: c1(:,:), c2(:,:)
    integer :: c(size(c1(:,1))+size(c2(:,1)),size(c2(1,:)))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1(:,1))
    n2 = size(c2(:,1))
    do while ((i1.le.n1).and.(i2.le.n2))
      if (c1(i1,1).le.c2(i2,1)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2,:) = c1(i1:n1,:)
    else if (i2.le.n2) then
      c(i1+i2-1:n1+n2,:) = c2(i2:n2,:)
    end if
    c1 = c(1:n1,:)
    c2 = c(n1+1:n1+n2,:)
    return
  end subroutine merger
end program sandglass

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
 
void Delete(int x,deque<int> &que){
    stack<int>a;
    while(!que.empty()){
        int i=que.front();
        que.pop_front();
        if(i==x) break;
        else a.push(i);
    }
    while(!a.empty()){
        que.push_front(a.top());
        a.pop();
    }
}

int main(){
    int n;
    scanf("%d",&n);
    deque<int>que;
    for(int i=0;i<n;i++){
        char str[20];
        scanf("%s",str);
        int x;
        if(str[0]=='i'){
            scanf("%d",&x);
            que.push_front(x);
        }
        else if(strlen(str)<=6) {
            scanf("%d",&x);
            Delete(x,que);
        }
        else{
            if(str[6]=='F'){
                que.pop_front();
            }
            else{
                que.pop_back();
            }
        }
    }
    while(!que.empty()){
        int x=que.front();
        que.pop_front();
        if(!que.empty()){
            cout << x << " ";
        }
        if(que.empty()){
            cout << x;
        }
    }
    cout << endl;
}


Measured memory_bytes: 6988
struct MyIo{

}

impl MyIo{
    fn readline()->Vec<String>{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let ret:Vec<String> = buf.split_whitespace().map(|c|c.to_string()).collect();
        ret
    }
}


fn main() {

    let mut input = MyIo::readline().into_iter();
    let N = input.next().unwrap().parse::<u32>().unwrap();

    if N%2==0{
        println!("{:?}",N);
    }else{
        println!("{:?}",N*2);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin >>W >>H >>x >>y >>r;
  if(x>=r && x<=(W-r) && y>=r && y<=(H-r)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3104