akhauriyash/Code-Regression huggingface dataset:
package main

import (
        "fmt"
)

func solution(n, m, x int, a []int) int {

        memo := make(map[int]bool, m)
        for i := 0; i < m; i++ {
                memo[a[i]] = true
        }
        fcost := 0
        for i := x; i <= n; i++ {
                if memo[i] {
                        fcost++
                }
        }

        bcost := 0
        for i := x; i >= 0; i-- {
                if memo[i] {
                        bcost++
                }
        }
        return min(bcost, fcost)
}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func main() {
        var n, m, x int
        fmt.Scan(&n, &m, &x)
        a := make([]int, 0, m)

        for i := 0; i < m; i++ {
                t := 0
                fmt.Scan(&t)
                a = append(a, t)
        }
        fmt.Println(solution(n, m, x, a))
}

Measured memory_bytes: 512
//Fairness

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;


int main (){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    d%=2;
    cout << (d ? b-a :a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
  int answer = 0;
  int plus_count = 0;
  int minus_count = 0;
  char input[10];
  scanf("%s",input);
  int i;
  for (i = 0;i < 4;++i) {
    if (input[i] == '+') {
      ++plus_count;
    } else {
      ++minus_count;
    }
  }
  answer = plus_count - minus_count;
  printf("%d\n",answer );
  return 0;
}

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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    for(int i=0;i<M;i++) cin >> p[i] >> S[i];

    for(int i=0;i<M;i++) p[i]-=1;

    vector<int> AC(N,0);
    vector<int> Penab(N,0);
    int ACtotal=0, Penalty=0;
    for(int i=0;i<M;i++){
        if(S[i]=="WA"&&AC[p[i]]==0) Penab[p[i]]++;
        if(S[i]=="AC") AC[p[i]]=1;
    }

    for(int i=0;i<N;i++){
        if(AC[i]==1){
            ACtotal++;
            Penalty += Penab[i];
        }
    }

    cout << ACtotal << " " << Penalty << endl;

    return 0;
}


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

int main() {
	//int n,a,b;
	string n;

	cin >> n  ;
	
	
	if ((n[0]==n[1] && n[0]==n[2]) ||
		(n[1] == n[2] && n[1] == n[3])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int cnt = 0;
		for(int i = 0; i < str.length() - 1; i++) {
			//System.out.println(str.substring(i, i + 1));
			//System.out.println(str.substring(i + 1, i + 2));
			if(str.substring(i, i + 1).equals(str.substring(i + 1, i + 2))) {
				cnt++;
				if(cnt >= 2) {
					System.out.println("Yes");
					return;
				}
			} else {
				cnt = 0;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define GET_BIT(n, i) (((n) & (1LL << ((i)-1))) >> ((i)-1)) // i start from 1
#define SET_BIT(n, i) ((n) | (1LL << ((i)-1)))
#define CLR_BIT(n, i) ((n) & ~(1LL << ((i)-1)))
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
void myInit();
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int MOD = 1000000007;
const int N = 3e5, M = N;
//=========TQR==============
vi g[N];

int main() {
	myInit();
	FIO;
	int i, n;
	cin >> n;
	vi a(n), lMax(n);
	ll ans = 0;
	fo(i, n) {
		cin >> a[i];
		if (i == 0) {
			lMax[0] = 0;
		}
		else {
			lMax[i] = max(a[i - 1], lMax[i - 1]);
		}
		if (lMax[i] > a[i]) {
			ans += lMax[i] - a[i];
		}
	}
	cout << ans << endl;

	return 0;
}

void myInit() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp) {
	base %= MOD;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % MOD;
		base = ((ll)base * base) % MOD;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 11892
#include <iostream>
#include <algorithm>

int main()
{
	int n; std::cin >> n;
	
	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	int m; std::cin >> m;
	
	int* B = new int[m];
	for (int i=0; i<m; i++) std::cin >> B[i];
	
	if (std::includes(A, A+n, B, B+m)) std::cout << 1 << std::endl;
	else std::cout << 0 << std::endl;
	
	delete[] A;
	delete[] B;
	
	return 0;
}



Measured memory_bytes: 4384
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
int main(){
    char str;
    while(1){
        if(str == '\n') break;
        scanf("%c",&str);
        if(isalpha(str)){
            if(islower(str)) printf("%c", toupper(str));
            else printf("%c",tolower(str));
        }
        else printf("%c",str);
    }
    return 0;
    
}



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

using namespace std;

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

long long f(long long x, long long c) {
    return x / c;
}

long long f(long long a, long long b, long long c) {
    return f(b, c) - f(a - 1, c);
}


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

    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long lcmcd = lcm(C, D);

    //cout << f(A, B, C) << " " << f(A, B, D) << " " << f(A, B, lcmcd) << endl;

    cout << (B - A + 1) - (f(A, B, C) + f(A, B, D) - f(A, B, lcmcd)) << "\n";

    return 0;
}

Measured memory_bytes: 256
while 1:
 n=int(input())
 if n==0:break;
 a=[]
 for i in range(n):
  a+=[list(map(int,input().split()))]
  a[i]+=[sum(a[i])]
  for s in a[i]:print("%5d"%s,end='')
  print()
 for c in zip(*a):print("%5d"%sum(c),end='')
 print()


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector <int> B(M);
  for (int i = 0; i < M; i++) cin >> B.at(i);
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    vector <int> A(M);
    for (int j = 0; j < M; j++) { 
      cin >> A.at(j);
    }
    int check = C;
    for (int j = 0; j < M; j++) check += A.at(j)*B.at(j);
    if (check > 0) ans ++;
  }
  cout << ans << endl;
}

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

int main(){

  int N,B;

  cin >> N;

  vector<int> A(N);
  string S;

  for(int i=0; i < N; i++){

    cin >> A.at(i);

  }
  
  sort(A.begin(),A.end());

  S = "YES";
  for(int i=0; i < N-1; i++){

    if(A.at(i) == A.at(i+1)){
      S = "NO";
      break;
    }

  }

cout << S;

}


Measured memory_bytes: 1024
sa = list(input())
sb = list(input())
sc = list(input())

turn = 'a'

while True:
  if turn =='a':
    if len(sa) !=0:
      turn = sa.pop(0)
    else:
      print('A')
      exit()
  elif turn =='b':
    if len(sb) !=0:
      turn = sb.pop(0)
    else:
      print('B')
      exit()
  elif turn =='c':
    if len(sc) !=0:
      turn =sc.pop(0)
    else:
      print('C')
      exit()

Measured memory_bytes: 3064
n,a,b;long h[1<<17];
f(long t)
{
	long c=0,i=0;
	for(;i<n;i++)c+=h[i]>b*t?ceil((h[i]-b*t)*1./(a-b)):0;
	return c>t;
}
main()
{
	int i=0,s=0,l=1e9,m;
	for(scanf("%d%d%d",&n,&a,&b);~scanf("%d",h+i++););
	for(i=0;i++<99;)f(m=(s+l)/2)?s=m:(l=m);
	printf("%d",l+f(l));
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
bool f[200005], f2[200005];
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m ; ++i){
        scanf("%d%d", &x, &y);
        // if(y < x) swap(x, y);
        if(x == 1)
            f[y] = 1;
        if(y == n)
            f2[x] = 1;
    }
    for(int i = 2; i < n ; ++i){
        if(f[i] == 1 && f2[i] == 1) {
printf("POSSIBLE"); 
return 0;
}
    }
    printf("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}


void oneCase () {
    int k, s;
    cin >> k >> s;
    int res = 0;
    for (int x = 0; x <= k; ++x) {
        for (int y = 0; y <= k; ++y) {
            res += ((s - x - y >= 0) && (s - x - y) <= k);
        }
    }
    cout << res << "\n";
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
      input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     int x = sc.nextInt();
     
     int y = sc.nextInt();
     
      while(!(x == 0 && y == 0))
     {
       if(x > y)
       {
         int box = x;
          
         x = y;
         
         y = box;
       } 
       output(x,y);
       
       x = sc.nextInt();
       
       y = sc.nextInt();
      }
   }
  static void output(int x,int y)
    {
     System.out.printf("%d %d",x,y); 
     
     System.out.println();
   }
 }
    


Measured memory_bytes: 39016
#include "cstring"
#include "iostream"

using namespace std;

int main()
{
	int N;
	int t,i,p=0;
	int yakusu=0;
	int sosuu[5555];
	int answer[55];
	int count = 0;
	cin >> N;
	for (t = 2; t <= 55555; t++) {
		yakusu = 0;
		for (i = 2; i <= t; i++) {
			if (t%i == 0)
				yakusu++;
		}
		if (yakusu == 1) {
			if (t % 5 == 1) {
				answer[count] = t;
				count+=1;
			}
		}
		if (count == N)
			break;
	}

	for (int s = 0; s < N; s++) {
		cout << answer[s]<<" ";
	}




	return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

constexpr auto mod = 1'000'000'007;

int main() {
    int n, k;
    cin >> n >> k; // 100'000

    auto edge = vector<vector<int>>(n + 1);
    for (auto i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    auto distance = vector<int>(n + 1, -1);
    auto q = vector<int>(n + 1);
    auto push = 0;
    auto pop = 0;
    q[push++] = 1;
    distance[1] = 0;
    auto cases = large{k};
    while (pop < push) {
        auto v = q[pop++];
        auto d = distance[v] + 1;
        auto children = 0;

        auto x = k + (v == 1) - 2;

        for (auto n : edge[v]) {
            if (distance[n] < 0) {
                distance[n] = d;
                q[push++] = n;
                ++children;

                cases *= x;
                cases %= mod;
                x--;
            }
        }

        if (cases == 0)
            break;
    }

    cout << cases << endl;
    return 0;
}


Measured memory_bytes: 9824
n,m = map(int,input().split())
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
L.sort(reverse=True)
R.sort()
ans =0
for i in range(n+1):
    if i >=L[0] and i <=R[0]:
        ans +=1
print(ans)

Measured memory_bytes: 11436
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        var count = new long[100001];
        long sum = 0;
        for(int i = 0; i < n; i++){
            int a = Integer.parseInt(sc.next());
            count[a]++;
            sum += a;
        }
        
        int q = Integer.parseInt(sc.next());
        var sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            sum -= count[b] * b;
            sum += count[b] * c;
            sb.append(sum).append(System.lineSeparator());
            count[c] += count[b];
            count[b] = 0;
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 61664
N=int(input())
A=list(map(int, input().split()))
L=[0]*(2**20)
for a in A:
    L[a]+=1

"""
for a  in A:
    b=bin(a)[2:]
    add=20-len(b)
    print("0"*add + b)
"""
ans=0
right=0
SUM=0
xor=-1
for left in range(N):
    while right<N and ((SUM+A[right]==(xor^A[right])) or (xor==-1)):
        if xor==-1:
            xor=A[left]
        else:
            xor=xor^A[right]
        SUM+=A[right]
        right+=1
    ans+=right-left
    #print(SUM, xor)
  
    SUM-=A[left]
    xor=A[left]^xor

print(ans)




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

using namespace std;
using namespace placeholders;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA ...a) {
  while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator<<(ostream &os, vector <T> v) {
  os << "[";
  for (auto vv : v) os << vv << ",";
  return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair <L, R> p) {
  return os << "(" << p.first << "," << p.second << ")";
}

#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

const int N = 110;

string s;

void run() {
  cin >> s;
  string ans;
  for (int i = 0; i < s.length(); ++i) {
    if (s.substr(i, s.length()) == "FESTIVAL") {
      ans = s.substr(0, i);
    }
  }
  cout << ans << endl;
}

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


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
ll fact[N];
ll mod = 1e9 + 7;
ll inv(ll u, ll p){
        if (p == 0) return 1;
        if (p == 1) return u;
        ll t = inv(u, p / 2) % mod;
        if (p & 1) return t * t % mod * u % mod;
        else return t * t % mod;
}
ll path(ll m, ll n){
        return fact[m + n - 2] * inv(fact[n - 1], mod - 2) % mod * inv(fact[m - 1], mod - 2) % mod;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen("WALKING.INP", "r")){
                freopen("WALKING.INP", "r", stdin);
                freopen("WALKING.OUT", "w", stdout);
        }
        fact[0] = 1;
        ll h, w, a, b;
        cin >> h >> w >> a >> b;
        for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % mod;
        ll ans = 0;
        ll cur = 0;
        for (int i = b + 1; i <= w; i++){
                ans += path(h - a, i)* path(a, w - i + 1);
                ans %= mod;
        }
        cout << ans;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))

tmp = 0
count = 0

for i in range(N):
	if tmp == 0:
		if A[i] == 1:
			tmp = A[i]
		else:
			count += 1
	else:
		if A[i] == tmp+1:
			tmp = A[i]
		else:
			count += 1
if tmp == 0:
	print(-1)
else:
	print(count)

Measured memory_bytes: 26012
def count(n, b):
  res = 0
  while n:
    res += n % b
    n //= b
  return res

def main():
  res = float('inf')
  for i in range(n + 1):
    res = min(res, count(i, 6) + count(n - i, 9))
  print(res)
 
if __name__ ==  '__main__':
  n = int(input())
  main()

Measured memory_bytes: 2940
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		long ans = 0;
		long root = (long) Math.sqrt((double) n);
		for (int i = 1; i <= root; i++) {
			if ((n - i) % i == 0 && (n - i) / i > i) {
				ans += (n - i) / i;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
A, B, M = map(int, input().split())
PA = [int(x) for x in input().split()]
PB = [int(x) for x in input().split()]
XYC = [tuple(map(int, input().split())) for _ in range(M)]

p1 = min(PA) + min(PB)
p2 = 10 ** 10
for x, y, c in XYC:
    p2 = min(PA[x - 1] + PB[y - 1] - c, p2)

print(min(p1, p2))

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

int main(){
  int n, m;
  cin >> n >> m;
  int ans = -1;
  int a[m], b[m];
  vector<int> c(m,0);
  rep(i,m){
    cin >> a[i] >> b[i];
    rep(j,b[i]) {
      int x;
      cin >> x;
      x--;
      c[i] += (1<<x);
    }
  }
  vector<vector<int>> dp(m+1,vector<int>((1<<n),INF));
  dp[0][0] = 0;
  rep(i,m){
    rep(j,1<<n){
      dp[i+1][j] = min(dp[i][j],dp[i+1][j]);
      dp[i+1][c[i]|j] = min(dp[i+1][c[i]|j],dp[i][j]+a[i]);
    }
  }
  if(dp[m][(1<<n)-1] == INF) cout << -1 << endl;
  else cout << dp[m][(1<<n)-1] << endl;
  return 0;
}

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

int main(){

	int n;
	cin >> n;
	long long ans[87];
	ans[0] = 2;
	ans[1] = 1;
	for(int i = 2; i <= n; i++)
	{	
		ans[i] = ans[i-1] + ans[i-2];
	}
		
	cout << ans[n] << endl;
	return 0;
}

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

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

	set<string> S;
	string si;

	for (int i = 0; i < N; i++)
	{
		cin >> si;
		S.insert(si);
	}

	cout << S.size();
}

Measured memory_bytes: 19116
#include<bits/stdc++.h>
using namespace std;
#define MAX 25

int v[MAX], c[MAX];
int main()
{
    int n;
    cin >> n;

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

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

    int sum = 0;

    for(int i = 0; i < n; i++){
        if(v[i] > c[i])
        sum += (v[i]-c[i]);
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

int a, b;
char op;

while(1){
scanf("%d %c %d", &a, &op, &b);
if (op == '+'){
        printf("%d\n", a + b);}
else if (op == '-'){
        printf("%d\n", a - b);}
else if (op == '*'){
        printf("%d\n", a * b);}
else if (op == '/'){
        printf("%d\n", a / b);}
else if (op == '?') break;
}
return 0;}

Measured memory_bytes: 600
def main():
    X , N = map(int, input().split())
    Pl = [A for A in input().split()]
    Pl = list(map(int, Pl))
    #print(Pl)
    for i in range(200) :
        Xp = X + i
        Xm = X - i
        if Xp not in Pl and Xm not in Pl :
            ans = min(Xp,Xm)
            break
        elif Xm not in Pl and Xp in Pl :
            ans = Xm
            break
        elif Xp not in Pl and Xm in Pl :
            ans = Xp
            break
        else :
            pass
    print(ans)




if __name__ == '__main__':
    main()


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

int main(){
	int n;cin>>n;
	ll U=ppow(10,n);
	ll A=ppow(9,n)*2%MOD;
	ll B=ppow(8,n)%MOD;
	cout<<(U+MOD-A+B)%MOD<<endl;
}

Measured memory_bytes: 3564
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int par[MAXN], _size[MAXN];
vector<pii> X, Y;
vector<pair<int, pii> > ed;
int n, x[MAXN], y[MAXN];

int getpar(int u) {
	while (u != par[u]) {
		par[u] = par[par[u]];
		u = par[u];
	}
	return u;
}

int chich(int a, int b) {
	int A = getpar(a), B = getpar(b);
	if (A == B) return 0;
	if (_size[A] > _size[B]) swap(A, B);
	par[A] = B;
	_size[B] += _size[A];
	return 1;
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> n;
	
	for (int i=0; i<n; i++) cin >> x[i] >> y[i];
	
	for (int i=0; i<n; i++) {
		X.pb(mp(x[i], i));
		Y.pb(mp(y[i], i));
	}
	
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	
	for (int i=1; i<n; i++) {
		ed.pb(mp(X[i].FI - X[i - 1].FI, mp(X[i].SE, X[i - 1].SE)));
		ed.pb(mp(Y[i].FI - Y[i - 1].FI, mp(Y[i].SE, Y[i - 1].SE)));
	}

	for (int i=0; i<n; i++) {
		par[i] = i;
		_size[i] = 1;
	}
	sort(ed.begin(), ed.end());
	
	ll ans = 0;
	for (int i=0; i<sz(ed); i++) {
		if (chich(ed[i].SE.FI, ed[i].SE.SE)) ans += (ll) ed[i].FI;
	}
	
	cout << ans;
}


Measured memory_bytes: 7912
#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int n,m;



bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}





int main(){
  int ans=0;
  cin >> n >> m;
  vector<pair<int,int>> a(m);
  REP(i,m){
    int i1,i2;
    cin>>i1>>i2;
    a[i].first=i1-1;
    a[i].second=i2-1;
  }

  sort(a.begin(),a.end(), compare_by_b);

  int bndnp=a[0].second-1;
  ans++;
  for(int i=1;i<m;i++){
    if (a[i].first>bndnp){
      bndnp=a[i].second-1;
      ans++;
    }
  }
  cout<<(ans)<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}

void bfs(int x,int y)
{
    
}
int main()
{
        string a,b;
        cin>>a>>b;  
        int dp[3005][3005];
            memset(dp,0,sizeof dp);
        
        for(int i=1;i<=a.length();i++)
        {
            for(int j=1;j<=b.length();j++)
            {
                if(b[j-1]==a[i-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
            }
        }
            int cnt=dp[a.length()][b.length()];
            string ans="";
            int x=a.length();int y=b.length();
            while(x&&y)
			{
				if(dp[x][y]==dp[x-1][y])x--;
				else if(dp[x][y]==dp[x][y-1])y--;
				else
				{
					ans=a[x-1]+ans;
					x--;
					y--;
				}
				
			}
            cout<<ans<<endl;
                
            
        
        
    return 0;
}



Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
ll num = pow(10,9) + 7;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	vector<vector<ll>> m(n+1, vector<ll>(3));
	ll ans(1);
	rep(i,n){
		int cnt(0);
		rep(j,3){
			m[i+1][j] = m[i][j];
			if(m[i+1][j] == a[i]){
				cnt++;
				if(cnt == 1) m[i+1][j]++;
			}
		}
		ans = (ans * cnt) % num;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define N 510
using namespace std;
typedef pair<int,int> P;
int h,w;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
bool mp[N][N][4],used[N][N],gxy[N][N];

bool onEdge(int x,int y){return (!x||!y||x==w+1||y==h+1);}
bool check(int x,int y){
  bool f[2]={};
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    f[mp[y][x][i]]|=(onEdge(nx,ny)||used[ny][nx]);
  }
  return f[0]&&f[1];
}


bool bfs(){
  memset(used,0,sizeof(used));
  queue<P>Q; 
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++) 
      if(check(j,i))Q.push(P(j,i)),used[i][j]=1;
  
  while(!Q.empty()){
    P t=Q.front();Q.pop();
    int x=t.first,y=t.second;
    if(gxy[y][x])return 1;
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(onEdge(nx,ny)||used[ny][nx]||!check(nx,ny))continue;
      Q.push(P(nx,ny));
      used[ny][nx]=1;
    }
  }
  return 0;
}

int main(){
  while(1){
    int sy,sx; 
    cin>>h>>w>>sy>>sx;
    if(!h&&!w&&!sy&&!sx)break;
    for(int i=1;i<=h+1;i++){
      for(int j=1,a;j<=w;j++)cin>>a,mp[i-1][j][2]=mp[i][j][0]=a;
      for(int j=1,a;j<=w+1&&i<h+1;j++)cin>>a,mp[i][j-1][1]=mp[i][j][3]=a;
    }
    
    memset(gxy,0,sizeof(gxy));
    bool ans=0;
    for(int i=0;i<4;i++){
      int nx=sx+dx[i],ny=sy+dy[i];
      if(!mp[sy][sx][i])gxy[ny][nx]=1,ans|=onEdge(nx,ny);
      }
    cout <<(ans||bfs()? "Yes":"No")<<endl;
  }
  return 0;

}

Measured memory_bytes: 4688
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

int main() {
    string s;
    cin >> s;
    FOR(i, s.length() - 1) {
        if (s[i] == 'B' && s[i + 1] == 'C') {
            if (i == 0)s = 'D' + s.substr(i + 2, s.length() - i - 2);
            else if (i == s.length() - 2)s = s.substr(0, i) + 'D';
            else s = s.substr(0, i) + 'D' + s.substr(i + 2, s.length() - i - 2);
        }
    }
    vector<string> t;
    FOR(i, s.length()) {
        if (s[i] == 'A' || s[i] == 'D') {
            for (int j = i; j < s.length(); j++) {
                if (s[j] == 'B' || s[j] == 'C') {
                    t.push_back(s.substr(i, j - i));
                    i = j;
                    break;
                }
                if (j == s.length() - 1) {
                    t.push_back(s.substr(i, j - i + 1));
                    i = j;
                }
            }
        }
    }
    ll ans = 0;
    for (string i : t) {
        int cnt = 0;
        FOR(j, i.length()) {
            if (i[j] == 'A') {
                ans += i.length() - j - 1;
                cnt++;
            }
        }
        FOR1(j, cnt)ans -= j;

    }
    cout << ans << endl;
}


Measured memory_bytes: 3176
M, D  = [int(v) for v in raw_input().split()]
p = 0
for m in range(1, M+1):
    for d in range(22, D + 1):
        d1 = d %10
        d10 = (d //10) % 10
        if d1 >= 2 and d10 >= 2 and d1 * d10 == m:
            p += 1
           # print('{}-{}'.format(m, d))
print(p) 

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  VVI card(3, VI(3));
  int n;
  bool flg = false;
  REP(i, 3) REP(j, 3) cin >> card[i][j];
  cin >> n;
  REP(i, n)
  {
    int b;
    cin >> b;
    REP(i, 3) REP(j, 3) if (card[i][j] == b) card[i][j] = 0;
  }
  int ct = 0, ct2 = 0;
  REP(i, 3)
  {
    if (card[i][i] == 0) ct++;
    if (card[i][2-i] == 0) ct2++;
    if (card[i][0] == 0 && card[i][1] == 0 && card[i][2] == 0) flg = true;
    if (card[0][i] == 0 && card[1][i] == 0 && card[2][i] == 0) flg = true;
  }
  if (ct == 3 || ct2 == 3) flg = true;
  if (flg) cout << "Yes";
  else cout << "No";

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define rep(i,x) for(int i=1;i<=(int)(x);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
/*
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
*/
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

typedef vector<double> Array;
typedef vector<Array> Matrix;

ostream& operator<<(ostream &os, const Array &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
ostream& operator<<(ostream &os, const Matrix &t) {
FOR(it,t)os<<*it<<endl;return os;
}


const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int p, q;
char str[1024];
main(){
	while(cin >> p >> q, p){
		Matrix m, n;
		int r=0, c=0, s=0;
		REP(i, p){
			cin >> str;
			char *pp = str;
			int ind = 0;
			for(;*pp=='.';pp++)ind++;
			Array a(4);
			a[0] = r;
			a[1] = c;
			a[2] = s;
			a[3] = ind;
			m.push_back(a);
			for(;*pp;pp++){
				if(*pp=='(') r++;
				if(*pp==')') r--;
				if(*pp=='{') c++;
				if(*pp=='}') c--;
				if(*pp=='[') s++;
				if(*pp==']') s--;
			}
		}
		r=0, c=0, s=0;
		REP(i, q){
			cin >> str;
			char *pp = str;
			int ind = 0;
			Array a(3);
			a[0] = r;
			a[1] = c;
			a[2] = s;
			n.push_back(a);
			for(;*pp;pp++){
				if(*pp=='(') r++;
				if(*pp==')') r--;
				if(*pp=='{') c++;
				if(*pp=='}') c--;
				if(*pp=='[') s++;
				if(*pp==']') s--;
			}
		}
		vector<int> ans(q, -2);
		rep(rr, 20)rep(cc, 20)rep(ss, 20){
			int f = 1;
			REP(i, p){
				if(m[i][0]*rr+m[i][1]*cc+m[i][2]*ss != m[i][3]){
					f = 0;
					break;
				}
			}
			if(!f) continue;
			REP(i, q){
				if(ans[i] == -2) ans[i] = n[i][0]*rr+n[i][1]*cc+n[i][2]*ss;
				else if(ans[i] != n[i][0]*rr+n[i][1]*cc+n[i][2]*ss) ans[i] = -1;
			}
		}
		REP(i, q) printf("%d%s", ans[i], i==q-1?"\n":" ");
	}
	return 0;
}

Measured memory_bytes: 1204
s = input()
seen = dict()
seen[0] = 1
curr = 0
mult = 1
out = 0
for c in s[::-1]:
    curr += int(c) * mult
    curr %= 2019
    mult *= 10
    mult %= 2019
    if curr not in seen:
        seen[curr] = 0
    out += seen[curr]
    seen[curr] += 1
print(out)


Measured memory_bytes: 68776
from sys import stdin
from collections import deque

def read_graph(n):
    A = [ [0]*(n+1) for _ in range(n+1) ]
    for _ in range(n):
        line = deque(stdin.readline().strip().split())
        i = line.popleft()
        line.popleft()
        for k in line:
            A[int(i)][int(k)] = 1
    return A

def dfs_ctrl(n, A):
    color = ["WHITE"] * (n+1)
    d = [0] * (n+1)
    f = [0] * (n+1)
    time = 0

    def dfs(u):
        nonlocal color
        nonlocal time
        if color[u] == "WHITE":
            color[u] = "GRAY"
            time += 1
            d[u] = time

            for v in range(1, n+1):
                if A[u][v] and color[v] == "WHITE":
                    dfs(v)
            color[u] = "BLACK"
            time += 1
            f[u] = time

    for i in range(1, n+1):
        if color[i] == "WHITE":
            dfs(i)

    for i in range(1, n+1):
        print(i, d[i], f[i])

n = int(input())
A = read_graph(n)
dfs_ctrl(n, A)


Measured memory_bytes: 6136
#include <iostream>
int main(){
    int n;
    while(std::cin>>n){
        if(n==0){
            break;
        }
        else{
            int a[4];
            a[0]=n;
            for(int i=1;i<4;++i){
                std::cin>>a[i];
            }
            int b[4];
            for(int i=0;i<4;++i){
                std::cin>>b[i];
            }
            int c=0,d=0;
            for(int i=0;i<4;++i){
                for(int j=0;j<4;++j){
                    if(a[i]==b[j]){
                        if(i==j){
                            ++c;
                        }
                        else{
                            ++d;
                        }
                    }
                }
            }
            std::cout<<c<<" "<<d<<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n, m, c;
int l[100000];
int color, w;
priority_queue<P> que;	//w, color

int main() {
	int i;
	
	cin >> n >> m >> c;
	rep(i, c) cin >> l[i];
	rep(i, n) {
		cin >> color >> w;
		color--;
		que.push(P(w, color));
	}
	
	int ans = 0;
	while (!que.empty()) {
		P now = que.top(); que.pop();
		color = now.second;
		if (l[color] > 0 && m > 0) {
			l[color]--;
			m--;
			ans += now.first;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int Max_N=2510;
const LL INF=1e18;

struct edge{
	int from, to;
	LL cost;
	edge(int f, int t, LL c): from(f), to(t), cost(c) {}
};

bool available[Max_N];
bool visited[Max_N];
vector<vector<edge>> G;

void dfs(int n){
	visited[n]=true;
	for(auto e:G[n]){
		if(visited[e.to]) continue;
		dfs(e.to);
	}
}

int main(){
	int N, M, P;
	cin >> N >> M >> P;
	rep(i,N) available[i]=true;
	G.resize(N);
	vector<edge> edges;
	rep(i,M){
		int a, b;
		LL c;
		cin >> a >> b >> c;
		a--; b--; c-=P;
		edge e(a,b,-c);
		G[a].emplace_back(e);
		edges.emplace_back(e);
	}
	dfs(0);
	rep(i,N) if(visited[i]==false) available[i]=false;
	rep(i,N){
		rep(j,N) visited[j]=false;
		dfs(i);
		if(visited[N-1]==false) available[i]=false;
	}
	vector<LL> dist(N,INF);
	dist[0]=0;
	rep(n,N){
		rep(i,M){
			edge e=edges[i];
			if(available[e.from]==false) continue;
			if(available[e.to]==false) continue;
			if(dist[e.to]>dist[e.from]+e.cost){
				dist[e.to]=dist[e.from]+e.cost;
				if(n==N-1){
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	if(dist[N-1]>0) cout << 0 << endl;
	else cout << -dist[N-1] << endl;

	return 0;
}

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

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;

  for(int i = 0; i < (int)s.size(); i++) {
    int l = s[i] - 65;
    l += n;
    l %= 26;
    s[i] = l + 65;
  }

  cout << s << endl;
  
  return 0;
}


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

int ilog2(int n) {
  int r = 0;
  while ((n & 1) == 0) {
    ++r;
    n >>= 1;
  }
  return r;
}

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

  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ret += ilog2(a);
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a: [[usize; 3]; 3],
        n: usize,
        b: [usize; n]
    }

    solve(a, &b);
}

fn solve(a: Vec<Vec<usize>>, b: &[usize]) {
    let mut flags = [[false; 3]; 3];

    for i in 0..3 {
        for j in 0..3 {
            for &item in b.iter() {
                if item == a[i][j] {
                    flags[i][j] = true;
                }
            }
        }
    }

    for i in 0..3 {
        if flags[i][0] && flags[i][1] && flags[i][2] {
            println!("Yes");
            return;
        }
    }
    for i in 0..3 {
        if flags[0][i] && flags[1][i] && flags[2][i] {
            println!("Yes");
            return;
        }
    }
    if flags[0][0] && flags[1][1] && flags[2][2] {
        println!("Yes");
        return;
    }
    if flags[2][0] && flags[1][1] && flags[0][2] {
        println!("Yes");
        return;
    }

    println!("No");
}


Measured memory_bytes: 2120
#include<stdio.h>

int main(void){

int a,b;

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

if(a < b){

printf("a < b\n");

}

if(a > b){

printf("a > b\n");

}

if(a == b){

printf("a == b\n");

}

return 0;

}

Measured memory_bytes: 580
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int a,b,c;
int main() {
	cin>>a>>b>>c;
	cout<<min(a+b+1,c)+b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, a[100], b[100], i, t=0;
    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i] != i)
            t++;
    }
    if(t < 3)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

ll a[15][15];
ll c[15] , p[15];
ll x,cost,n,m,ans;
void dp(ll pos){
	if(pos > n) return; 
   dp(pos+1);
   f0(m) p[i] += a[pos][i];
   cost += c[pos];
   bool ok = 0;
   for(ll i = 0; i < m; i++){
   	  if(p[i] < x) ok = 1;
   }
   if(!ok){
   	 for(ll i = 0; i < m; i++) p[i] -= a[pos][i];
   	 ans = min(ans , cost);
   	 cost -= c[pos];
   	 return;
   }
   dp(pos+1);
   for(ll i = 0; i < m; i++) p[i] -= a[pos][i];
   cost -= c[pos];
   return;
}

void solve(){ 
    cin >> n >> m >> x;
    f0(n){
    	cin >> c[i];
    	f00(m) cin >> a[i][j];
	}
	mem(p,0);
	ans = INF;
	cost = 0;
	dp(0);
	if(ans == INF) cout << "-1";
	else cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 3640
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

stack = []
lack = 0
count = 0

if  sum(A) >= sum(B) :
    for i in range(N) :
        if A[i] < B[i] :
            count += 1
            lack += B[i] - A[i]

        elif A[i] > B[i] :
            stack.append(A[i] - B[i])
    stack.sort(reverse=True)
    if count != 0 :
        for j in range(len(stack)) :
            lack -= stack.pop(0)
            count += 1
            if lack <= 0 :
                break
    print(count)

else :
    print(-1)


Measured memory_bytes: 18356
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define int  ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    int n; cin>>n;
    vector<vector<bool>>used(n,vector<bool>(n,true));
    vvi d(n,vi(n));
    rep(i,n)rep(j,n)cin>>d[i][j];
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][j]>d[i][k]+d[k][j])return puts("-1")*0;
    }
    int ans=0;
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][j]<d[i][k]+d[k][j])continue;
        if(i==j||k==j||k==i)continue;
        if(d[i][j]==d[i][k]+d[k][j]){
            used[i][j]=false;
        }
    }
    rep(i,n)rep(j,n)if(i!=j)if(used[i][j])ans+=d[i][j];
    cout<<ans/2<<endl;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
int main(void)
{
  char t1[1001],t2[8],t3[1001];
  int i,j,n,a,b;
 
  scanf("%s\n%d",t1,&n);
 
  for(i=0;i<n;i++){
    scanf("%s %d %d",t2,&a,&b);
     
    if(!strcmp(t2,"reverse")){
      for(j=a;j<=b;j++)
        t3[b-j]=t1[j];
      for(j=a;j<=b;j++)
        t1[j]=t3[j-a];
    }
 
    if(!strcmp(t2,"replace")){
      scanf("%s",t3);
      for(j=0;t3[j]!='\0';j++)
        t1[a+j]=t3[j];
    }
 
    if(!strcmp(t2,"print")){
      for(j=a;j<=b;j++)
        printf("%c",t1[j]);
      printf("\n");
    }
  }
 
  return 0;
}


Measured memory_bytes: 2048
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)
ans = 0
for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, a / 2)
print(-sum(int(a) for a in A))


Measured memory_bytes: 14180
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char s[5];
  scanf("%s", s);
  bool c = false;
  for (int i=1; i<3; i++) {
    if (s[0] == s[i])
      continue;
    c = true;
  }
  if (c)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 128