akhauriyash/Code-Regression huggingface dataset:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()

wt = []

for i in range(n):
    a, b = inintm()
    wt.append([a,b])

wt = sorted(wt, reverse=True, key=lambda x: x[1])[::-1]

t = 0

for j in range(n):
    t += wt[j][0]
    if t > wt[j][1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 42288
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner num = new Scanner(System.in);
        int a = num.nextInt();
        int b = num.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 26216
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
const int INF = 2100000000;

class Heap{
  public:
    vector<int> a;
    int N;
    Heap(int n){
      N = n;
      a.resize(N, INF);
      N--;
    }

    int get_parent(int x){
      return a[(x)/2];
    }

    int get_left(int x){
      if(x*2 < N){
        return a[x*2];
      }
      return INF;
    }

    int get_right(int x){
      if(x*2+1 < N){
        return a[x*2+1];
      }return INF;
    }

    void print(){
      cout << "debug print " << endl;
      for(int j = 1; j <= N; ++j){
        cout << " " << a[j];
      }cout << endl;
    }

  void mx(int i){
    int l = i*2;
    int r = i*2+1;
    int largest = INF;


    if(l <= N && a[l] > a[i]){
      largest = l;
    }else{
      largest = i;
    }

    if(r <= N && a[r] > a[largest])
        largest = r;

    if(largest != i){
      swap(a[i], a[largest]);
      mx(largest);
    }
  }

  void rmx(int i){
    int parent;
    int largest = INF;

    while(1){
      parent = i/2;
      if(parent < 1)
        break;

      if(a[parent] < a[i]){
        swap(a[parent], a[i]);
        i = parent;
        continue;
      }
      break;
    }
  }


  void buildMXHeap(){
//     cout << "build" << endl;
//       print();
    for(int i = N/2; i > 0; --i){
      mx(i);
    }
//       print();
  }

  void insert(int x){
    if( N+1 >= a.size())
      a.resize((N+1)*2, INF);

    N++;
    a[N] = x;
    rmx(N);
  }

  int extract(){
    int tmp = a[1];
    a[1] = a[N];
    a[N] = INF;
    N--;
    mx(1);
    return tmp;
  }
};




int main(void){
  int n, a;
  string str;
  Heap hp(1);

  while(1){
    cin >> str;
    if(str == "insert"){
      cin >> a;
//       cout << "INSERT" << endl;
      hp.insert(a);
    }else if(str == "extract"){
//       cout << "EXTRACT " << endl;
      cout << hp.extract() << endl;
    }else{
      break;
    }
//     cout << "end instruction " << endl;
//    hp.print();
  }

//   for(int i = 1; i < n; ++i){
//     cout << "node " << i << ": key = " << hp.a[i];
//     if(hp.get_parent(i) != INF){
//       cout << ", parent key = " << hp.get_parent(i);
//     }
//     if(hp.get_left(i) != INF){
//       cout << ", left key = " << hp.get_left(i);
//     }
//     if(hp.get_right(i) != INF){
//       cout << ", right key = " << hp.get_right(i);
//     }
//     cout << ", " << endl;
//   }

//   buildMXHeap(hp);
//   hp.print();
  return 0;
}

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

int main(void){
    char s[120];
    scanf("%s",s);
    for (int i=0; i<strlen(s); i++){
        if (s[i]=='C'){
            for (int j=i; j<strlen(s); j++){
                if (s[j]=='F'){
                    printf ("Yes\n");
                    exit (0);
                }
            }
        }
    }
    printf ("No\n");
	return 0 ;
}

Measured memory_bytes: 128
from itertools import combinations_with_replacement
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum = 0
k = int(input())
l = range(1,k+1)

for a,b,c in combinations_with_replacement(l, 3):
    ans = gcd(a,b,c)
    if a == b and a == c:
        sum += ans
    elif a == b or b == c or c == a:
        sum += 3 * ans
    else:
        sum += 6 * ans

print(sum)

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

int main() {
  double N, K;
  cin >> N >> K;
  vector<double> persum(N);
  
  for (int i = 1; i <= N; i++) {
    double per = 1;
    int j = i;
    while(j < K) {
      j = 2*j;
      per = per*(0.5);
    }
    per = per*(1/N);
    persum.at(i-1) = per;
  }
  double ans = 0;
  for (int i = 0; i < N; i++) {
    ans += persum.at(i);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

   

Measured memory_bytes: 1024
def check(bag, mtx):
    shojiki = set()
    not_shojiki = set()
    for i in range(len(bag)):
        if bag[i] == 1:
            shojiki.add(i)
    shojiki_list = list(shojiki)
 
    while True:
        if shojiki_list == []:
            break
        i = shojiki_list.pop()
        for j in range(len(mtx[i])):
            if mtx[i][j] == 0 and j in shojiki:
                return False
            if mtx[i][j] == 1:
                if j in not_shojiki:
                    return False
                if j not in shojiki:
                    shojiki_list.append(j)
                    shojiki.add(j)
            if mtx[i][j] == 0:
                not_shojiki.add(j)
    return True
 
 
n = int(input())
 
mtx = [[-1] * n for i in range(n)]
 
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        mtx[i][x-1] = y
 
ret = 0
 
for i in range(2 ** n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(1)
        else:
            bag.append(0)
    if check(bag, mtx):
        if ret < sum(bag):
            ret = sum(bag)
 
print(ret)


Measured memory_bytes: 44764
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		
		//方針
		//数字とindexをpairとかで持っておき、数字ソート
		//loop
		//大きい順に、自分より大きい数字を一つ含む時の左と右の候補を計算
		//Treesetに自分のindexを入れる
		//loop
		int n = sc.nextInt();
		long ans = 0;
		ans = (long)(n-1)*(1+n-1)/2;
		System.out.println(ans);
	}


	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



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




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}


}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   otherpair.from - from;
	}








}






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

#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

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

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class AAtCoderGroupContest {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n;
	    in >> n;
	    vl a(3*n);
	    for(int i=0; i<3*n; i++){
	        in >> a[i];
	    }

	    sort(a.begin(), a.end(), greater<>());
	    ll res = 0;
	    ll cnt = 0;
	    ll cur = 1;
	    while(cnt < n){
            res += a[cur];
            cur += 2;
            cnt++;
	    }

	    out << res << enl;
	}
};


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


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

using namespace std;

int main()
{

	int H;
	int N;
	cin>>H>>N;
	vector<int> A(N);
	for (auto &x : A) {
		cin>>x;
	}

	int ans = accumulate(A.begin(), A.end(), 0);
	if (ans >= H) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 640
N, X = map(int, input().split())
layers = [0] * (N+1)
layers[0] = 1
patties = [0] * (N+1)
patties[0] = 1
for i in range(1, N+1):
    layers[i] = 2*layers[i-1] + 3
    patties[i] = 2*patties[i-1] + 1

def eat(n, x):
    if x <= 0:
        return 0
    if n == 0:
        return 1
    mid = layers[n-1] + 2
    if x < mid:
        return eat(n-1, x-1)
    return 1 + patties[n-1] + eat(n-1, x-mid)

print(eat(N, X))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
vector<vector<int>> warshall_floyd(vector<vector<edge>> G){
  int n = G.size();
  vector<vector<int>> dp(n, vector<int> (n, 1LL << 60));
  for(int i = 0; i < n; i++){
    for(edge e : G[i]){
      dp[i][e.to] = e.cost;
    }
    dp[i][i] = 0;
  }
  for(int k = 0; k < n; k++){ //経由する頂点
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  return dp;
}

vector<vector<int>> warshall_floyd2(vector<vector<int>> G, int l){
  int n = G.size();
  vector<vector<int>> dp(n, vector<int> (n, 1LL << 60));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(G[i][j] <= l) dp[i][j] = 1;
    }
    dp[i][i] = 0;
  }
  for(int k = 0; k < n; k++){ //経由する頂点
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  return dp;
}

signed main(){

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

  auto dp = warshall_floyd(G);
  auto dp2 = warshall_floyd2(dp, l);

  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int s,t; cin >> s >> t;
    s--,t--;
    cout << (dp2[s][t] >= (1LL << 60) ? -1 : dp2[s][t] - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  bool yymm = false, mmyy = false;
  if (s[2] == '0') {
    if ('1' <= s[3] && s[3] <= '9') yymm = true;
  } else if (s[2] == '1') {
    if ('0' <= s[3] && s[3] <= '2') yymm = true;
  }
  if (s[0] == '0') {
    if ('1' <= s[1] && s[1] <= '9') mmyy = true;
  } else if (s[0] == '1') {
    if ('0' <= s[1] && s[1] <= '2') mmyy = true;
  }
  if (yymm && mmyy) {
    cout << "AMBIGUOUS" << endl;
  } else if (yymm) {
    cout << "YYMM" << endl;
  } else if (mmyy) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;


const ll mod = 1e9+7;
const double eps = 1e-9;




void solve(){
    int s, w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


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

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

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

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    string s, t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();
    int ans = INT_MAX;
    for (int i = 0; i + m - 1 < n; ++i) {
        int cnt = 0;
        rep(j, m) {
            if (s[i+j] != t[j]) cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans << '\n';
}


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

int main(){
  int n;
  cin >> n;
  int total = 0;
  for (int i=0;i<n;i++){
    int l,r;
    cin >> l >> r;
    total += r - l + 1;
  }
  cout << total << endl;
  return 0;
}



Measured memory_bytes: 384
n, k, q = map(int, input().split())
pts = [k] * n
ans = [0] * n
a = []
for i in range(q):
    a = int(input())
    a -= 1
    ans[a] += 1

for i in range(n):
    pts[i] = pts[i] + ans[i] - q

for p in pts:
    if(p > 0):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8632
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;

inline void go_die() {
    exit(0 * puts("No"));
}

int n;
int ta[MAX_N], a[3][MAX_N], id[MAX_N], per[MAX_N];

inline void add(int x, int v) {
    for (; x; x -= x & -x) {
        ta[x] += v;
    }
}

inline int get(int x) {
    int ret = 0;
    for (; x <= n; x += x & -x) {
        ret += ta[x];
    }
    return ret;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < 3; ++i) {
        for (int j = 1; j <= n; ++j) {
            scanf("%d", a[i] + j);
        }
    }
    static int inv[2], flip[2];
    for (int i = 1; i <= n; ++i) {
        static int d[3];
        for (int j = 0; j < 3; ++j) {
            d[j] = a[j][i];
        }
        sort(d, d + 3);
        if (d[2] % 3 || d[1] != a[1][i]) {
            go_die();
        }
        if (d[0] + 1 != d[1] || d[1] + 1 != d[2]) {
            go_die();
        }
        int j = d[2] / 3;
        if ((i - j) % 2) {
            go_die();
        }
        (inv[i % 2] += a[0][i] > a[2][i]) &= 1;
        id[i] = j;
    }
    for (int i = 1; i <= n; ++i) {
        per[id[i]] = i;
    }
    for (int i = 1; i <= n; i += 2) {
        int now = per[i] + 2 * get(per[i]);
        (flip[1] += abs(i - now) / 2) &= 1;
        add(per[i], 1);
    }
    memset(ta, 0, sizeof ta);
    for (int i = 2; i < n; i += 2) {
        int now = per[i] + 2 * get(per[i]);
        (flip[0] += abs(i - now) / 2) &= 1;
        add(per[i], 1);
    }
    if (flip[0] != inv[1] || flip[1] != inv[0]) {
        go_die();
    }
    return 0 * puts("Yes");
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int C[10001][4],sumC[10001];
  int n,i,j,a,b,c,d,count;;

  while(1){
    count=0;
    for(i=0;i<10001;i++){
      for(j=0;j<4;j++){
	C[i][j]=0;
	sumC[i]=0;
      }
    }
    scanf("%d",&n);
    if(n==0)break;

    for(i=0;i<n+1;i++){
      for(j=0;j<4;j++){
	scanf("%d",&C[i][j]);
	if(i<n){
	if(j==1){
	  sumC[i]+=C[i][j]*4;
	}else if(j==2){
	  sumC[i]+=C[i][j]*9;
	}else if(j==3){
	  sumC[i]+=C[i][j]*4;
	}
	}else if(i==n){
	  a=C[i][0];
	  b=C[i][1];
	  c=C[i][2];
	  d=C[i][3];
      }
    }
    }
    for(i=0;i<n;i++){
	if(a>=C[i][1] && b>=C[i][2] && c>=C[i][3] && d>=sumC[i] ){
	  printf("%d\n",C[i][0]);
	  count++;
	}
    }
    if(count==0){
      printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll r,g,b,n,ans;
int main(){
	cin >> r >> g >> b >> n;
	for(ll i=0;i<=n;i+=r)
		for(ll j=0;i+j<=n;j+=g)
			if((n-i-j)%b==0)ans++;
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int N;
bool g[10][10];
bool seen[10];

int dfs(int now){
    bool all_seen = true;
    for(int i=1; i<=N; i++){
        if(seen[i] == false) all_seen = false;
    }
    if(all_seen) return 1;

    int res = 0;
    for(int to=1; to<=N; to++){
        if(g[now][to] == true && seen[to] == false){
            seen[to] = true;
            res += dfs(to);
            seen[to] = false;
        }
    }

    return res;
}

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

    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        g[a][b] = g[b][a] = true;
    }

    seen[1] = true;
    cout << dfs(1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll n;
ll A[SIZE];
ll K;

int main()
{
	int idx;
	ll s=0,t=0,b;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&A[i]);
		A[i] -= i;
	}
	sort(A,A+n);
	idx = n/2;
	b = A[idx];
	for(int i=0;i<idx;i++){
		s += (b-A[i]);
	}
	for(int i=(idx+1);i<n;i++){
		t += (A[i]-b);
	}
	printf("%lld\n",s+t);

	return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
using namespace std;
int W,H,ans,vis[105][105];
char mp[105][105];
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
bool check(int x,int y,char c){
    if(vis[x][y])return 0;
    if(mp[x][y]==c&&x&&y&&x<=H&&y<=W)return 1;
    return 0;
}
void dfs(int x,int y,char c){
    vis[x][y]=1;
    for(int i=0;i<4;i++){
        if(check(x+dx[i],y+dy[i],c))dfs(x+dx[i],y+dy[i],c);
    }return;
}
int main(){
    while(~scanf("%d%d",&H,&W),W+H){
        ans=0; memset(vis,0,sizeof(vis));
        for(int i=1;i<=H;i++)scanf("%s",mp[i]+1);
        for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)
        if(!vis[i][j]){ans++;dfs(i,j,mp[i][j]);}
        printf("%d\n",ans);
    }return 0;
}

Measured memory_bytes: 3252
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{

public static void main(String[] args) {

        Scanner s = new Scanner(new BufferedInputStream(System.in));
        int N = s.nextInt();
        long W = s.nextLong();
        long[] w= new long[N];
        int[] v = new int[N];

        for (int i = 0;i < N;i++ ) {
            w[i] = s.nextLong();
            v[i] = s.nextInt();
        }
        long[][] dp = new long[N+1][100001];
        for (int i = 0;i < N+1;i++) {
            for (int j = 0;j < 100001;j++) {
                dp[i][j] = Integer.MAX_VALUE;
            }
        }

        dp[0][0] = 0;
        for (int i = 0;i < N;i++) {
                for (int sumv = 0;sumv < 100001;sumv++)
                {
                    if (sumv >= v[i]) {
                        dp[i+1][sumv] = Math.min(dp[i+1][sumv],dp[i][sumv-v[i]]+w[i]);
                    }
                    dp[i+1][sumv] = Math.min(dp[i+1][sumv],dp[i][sumv]);
                }
        }

        long ans = 0;
        for (int i = 0;i < 100001;i++) {
            if (dp[N][i] <= W) {
                ans = i;
            }
        }
        System.out.println(ans);
    }
  
}


Measured memory_bytes: 127568
#include <bits/stdc++.h>
#define F(i,n) for (int i=1; i<=(int)n; i++)
#define FF(i,n) for (int i=0; i<(int)n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pi pair < int , int >
#define re(x) (int)x.size()
#define y1 u228
using namespace std;
typedef long long ll;
const int N = 100001;
const int big = 2e9;
const int md = 1e9 + 7;
int n,m,a,b,f[N];
vector < int > p[N],sp;
bool ok[N],mrk[N];
void dfs(int v){
    mrk[v]=1;
    FF(j,re(p[v])){
        int u=p[v][j];
        if (mrk[u]) continue;
        dfs(u);
    }
    sp.pb(v);
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin>>n>>m;
    F(i,m){
        int a,b;
        cin>>a>>b;
        p[a].pb(b);
        ok[b]=1;
    }
    F(i,n) f[i]=0;
    F(i,n){
        if (ok[i] || mrk[i]) continue;
        sp.resize(0);
        dfs(i);
        FF(j,re(sp)){
            int x=sp[j];
            FF(jj,re(p[x])){
                int u=p[x][jj];
                f[x]=max(f[x],f[u]+1);
            }
        }
    }
    int ans=0;F(i,n) ans=max(ans,f[i]);
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 11644
import java.util.Scanner;

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

		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();

		if (b == 0) {
			System.out.println(1);
			sc.close();
			return;
		}

		System.out.println(func(b, x) - func(a - 1, x));

		sc.close();
	}

	static long func(long n, long x) {
		if (n < 0)
			return 0;
		return n / x + 1;
	}
}



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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TC int tc; cin >> tc; while(tc--)

using namespace std;

const int INF = 1e9 + 7;

int n, k;
vector<long double> a;

bool ok(long double x){
	ll cnt = 0;
	for(auto i : a){
		cnt += max(ceil(i/x)-1, (long double)0);
	}
	//cout << cnt << ' ' << x << '\n';
	return cnt <= k;
}

int main(void)
{
	FAST
	cin >> n >> k;
	a = vector<long double>(n);

	for(auto &t : a) cin >> t;

	ll lo = 0, hi = 1e9+1;

	while(hi - lo > 1){
		ll mid = lo + (hi-lo)/2;
		if(ok((long double)mid))hi = mid;
		else lo = mid;
	}

	cout << hi << '\n';

	return 0;
}


Measured memory_bytes: 6404
#include<iostream>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	int sum = 0;
	for (int i = 0; i < 2; i++) {
		if (A>=B) {
			//Aが大きい
			sum = sum + A;
			A--;
		}
		else {
			//Bが大きい
			sum = sum + B;
			B--;
		}
	}

	cout << sum << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main() {
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
//#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int r = A - B;
	int ans = C - r;

	if (ans < 0) cout << 0 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
  using namespace std;
  int n;
  cin >> n;
  int * a = new int[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int maxv = -2000000000;
  int minv = a[0];
  for (int i = 1; i < n; i++)
  {
    maxv = maxv > (a[i] - minv) ? maxv : a[i] - minv;
    minv = minv < a[i] ? minv : a[i];
  }
  cout << maxv << endl;
  return 0;
}



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

int main(){

  int num;
  cin >> num;

  set<string> st;

  for(int i=0;i<num;i++){
    string nowStr;
    cin >> nowStr;
    st.insert(nowStr);
  }

  cout << st.size() << endl;

}

Measured memory_bytes: 19188
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long k, seven=7, i;
    cin >> k;
    for(i=1;i<=100000000;i++){
        if(seven%k==0){
            cout << i <<endl;
            return 0;
        }
        seven%=k;
        seven=seven*10+7;
    }

    cout << -1 <<endl;
    return 0;
}

Measured memory_bytes: 3608
import math
n = int(input())
d = list(map(int,input().split()))
count = 0
#print(d)

for i in range(n):
    #count += 1
    for j in range(n):
        if i == j:
            count += 0
        else :
            count += d[i] * d[j]
print(math.floor(count/2))

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

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

using namespace std;

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

    int n, d, x, ans = 0; cin >> n >> d >> x;
    REPI(i, n){
        int y; cin >> y;
        ans += d / y;
        if(d % y == 0) ans--;
    }cout << ans + n + x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long   

const ll mod=1e9+7;

int main()
{
  string s;
  ll a,b;
  sfl(a);
  sfl(b);
  cin>>s;
 ll i=0;
  ll flag=0;
  if(s[a]=='-')
  {
     while(s[i]!='\0')
     {
         if(i==a)
         {
             i=i+1;
             
         }
         
         else if((s[i]=='0'||s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9'))
            {
               flag=1;
            }
            
            else
            {
                flag=0;
                break;
            }
            i++;
     }
  }
  if(flag==1)
  {
    
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
  char a,b;
  cin >> a >> b;
  
  string sa(a - '0', (int)b);
  string sb(b - '0', (int)a);
  if (sa < sb) {
    cout << sa << endl;
  }
  else {
    cout << sb << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
     
    public void solve(){
		Scanner sc = new Scanner(System.in);
		
        int a,b;
		
		a = sc.nextInt();
		b = sc.nextInt();
		
		if(a < b){
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else if(a == b){
			System.out.println("a == b");
		}
    }

       public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
     }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int cnt1[2], cnt2[2];

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

    string s;
    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy";
    } else if (s == "Cloudy") {
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int soln(vector<vector<int>>a){
    int n=a.size();
    int dp[n][3];
    //base case
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    int i=n-1;
    return max(dp[i][0],max(dp[i][1],dp[i][2]));
}
int main() {
    int n;cin>>n;
    vector<vector<int>>a;
    for(int i=0;i<n;i++){
        int x,y,z;cin>>x>>y>>z;
        a.push_back({x,y,z});
    }
    cout<<soln(a);
}


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

int main(){
    int N ;
    cin >> N ;
    vector<int>p (N) ;
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i) ;
    }
    bool ans = false ;
    int temp = 0 ;
    for (int k = 0; k < N-1; k++)
            {
                if (p.at(k) > p.at(k+1))
                {
                    break ;
                }
                if (k == N-2)
                {
                    ans = true ;
                }
                
                
            }
    for (int i = 0; i < N-1; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            temp = p.at(i) ;
            p.at(i) = p.at(j) ;
            p.at(j) = temp ;

            for (int k = 0; k < N-1; k++)
            {
                if (p.at(k) > p.at(k+1))
                {
                    break ;
                }
                if (k == N-2)
                {
                    ans = true ;
                }
                
                
            }
            
            temp = p.at(i) ;
            p.at(i) = p.at(j) ;
            p.at(j) = temp ;
            if (ans== true)
            {
                break;
            }
            
        }
        if (ans == true )
        {
            /* code */
            break;
        }
        
    }
    if (ans == true)
    {
        cout << "YES" << endl ;
    }
    else
    {
        cout << "NO" << endl ;
    }
    
    
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		n     int
		count int
	)
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}
	flag := true
	for flag {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				flag = false
			}
		}
		if flag {
			count++
		}
	}
	fmt.Println(count)
}


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

#include <vector>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

typedef long long ll;

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &H[i]);
    }
    vector<vector<int>> graph(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    ll tot = 0;
    vector<bool> chk(N, false);
    for (int i = 0; i < N; i++) {
        if (graph[i].size() == 0) {
            tot++;
            continue;
        }
        if (chk[i] == true) {
            continue;
        }
        ll maxh = H[i];
        bool ok = true;
        chk[i] = true;
        for (auto j : graph[i]) {
            if (maxh <= H[j]) {
                ok = false;
            } else {
                chk[j] = true;
            }
        }
        if (ok) {
            tot++;
        }
    }
    cout << tot << endl;
    return 0;
}


Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  set<int>k;
  for(int i=0;i<N;i++){
    k.insert(A[i]);
  }
  if(k.size()%2!=0){cout<<k.size()<<endl;}
  else{cout<<k.size()-1<<endl;}
  return 0;
}

Measured memory_bytes: 8176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int x,y,z,k;
ll a[2000],b[2000],c[2000];
priority_queue<pair <ll,ll> > temp;
priority_queue<ll> q;
int main(){
    cin>>x>>y>>z>>k;
    for(int i=1;i<=x;i++)cin>>a[i];
    for(int i=1;i<=y;i++)cin>>b[i];
    for(int i=1;i<=z;i++)cin>>c[i];

    sort(a+1,a+1+x,greater<ll>());
    sort(b+1,b+1+y,greater<ll>());
    sort(c+1,c+1+z,greater<ll>());

    int A,B,C;
    A=1;B=1;C=1;
    while(A*B*C <= 10000000){
        if(A==x && B==y && C==z){
            break;
        }
        else{
            if(A<x){
                temp.push(make_pair(-1*(a[A]-a[A+1]),1));
            }
            if(B<y){
                temp.push(make_pair(-1*(b[B]-b[B+1]),2));
            }
            if(C<z){
                temp.push(make_pair(-1*(c[C]-c[C+1]),3));
            }
        }
        ll top = temp.top().second;
        if(top==1){A++;}
        else if(top==2){B++;}
        else{C++;}
        while(!temp.empty())temp.pop();
    }
    for(int i=1;i<=A;i++){
        for(int j=1;j<=B;j++){
            for(int l=1;l<=C;l++){
                q.push(a[i]+b[j]+c[l]);
            }
        }
    }
    for(int i=0;i<k;i++){
        cout<<q.top()<<endl;
        q.pop();
    }
}


Measured memory_bytes: 133468
using System;

namespace ALDS1_13_A
{
    class Program
    {
        const int N = 8;
        const int NOT_FREE = -1;
        const int FREE = 0;
        static int[] row = new int[N], col = new int[N], dpos = new int[2 * N - 1], dneg = new int[2 * N - 1];
        static bool[,] X = new bool[N, N];
        static void Main(string[] args)
        {
            var k = scan[0];
            for (int i = 0; i < k; i++)
            {
                var L = scan;
                X[L[0], L[1]] = true;
            }
            recursive(0);
        }
        static void recursive(int i)
        {
            if (i == N)
            {
                printBoard();
                return;
            }
            for (int j = 0; j < N; j++)
            {
                if (NOT_FREE == col[j] || NOT_FREE == dpos[i + j] || NOT_FREE == dneg[i - j + N - 1]) continue;
                row[i] = j;col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
                recursive(i + 1);
                row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
            }
        }
        static void printBoard()
        {
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (X[i, j] && row[i] != j) return;
                }
            }
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    Console.Write((row[i] == j) ? "Q" : ".");
                }
                Console.WriteLine();
            }
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  string s;
  cin >> s;

  int maxv = 0;
  for (int i = 1; i <= s.length(); ++i) {
    for (int j = 0; j <= s.length() - i; ++j) {

      string sb = s.substr(j, i);

      bool isOK = true;
      for (auto e : sb) {
        if (e != 'A' && e != 'C' && e != 'G' && e != 'T') isOK = false;
      }

      if (isOK) chmax(maxv, sb.length());

    }
  }

  cout << maxv << "\n";

  return 0;
}

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

int main()
{
  int N;
  int a[110];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i];

  int A=0, B=0;
  sort(a, a+N, greater<int>());

  rep(i,N){
    if(i%2==0) A+= a[i];
    else B+=a[i];
  }

  cout << A-B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> g(n);
        for (int i = 1; i < n; i ++) {
                int p;
                scanf("%d", &p);
                p --;
                g[p].push_back(i);
        }
        vector<int> x(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d", &x[i]);
        }
        vector<int> res(n);
        function<void (int)> dfs = [&](int u) {
                vector<int> dp(x[u] + 1, 1 << 30);
                dp[0] = 0;
                for (auto v : g[u]) {
                        dfs(v);
                        vector<int> prev = dp;
                        dp.assign(x[u] + 1, 1 << 30);
                        int a = x[v];
                        int b = res[v];
                        for (int i = 0; i < prev.size(); i ++) if (prev[i] < 1 << 30) {
                                if (i + a <= x[u]) dp[i + a] = min(dp[i + a], prev[i] + b);
                                if (i + b <= x[u]) dp[i + b] = min(dp[i + b], prev[i] + a);
                        }
                }
                int mi = 1 << 30;
                for (int i = 0; i < dp.size(); i ++) {
                        mi = min(mi, dp[i]);
                }
                res[u] = mi;
        };
        dfs(0);
        bool ans = res[0] < 1 << 30;
        puts(ans ? "POSSIBLE" : "IMPOSSIBLE");
        return 0;
}



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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cout << #x << "= " << x<< endl;
// template starts
typedef long long int ll;

// template ends here

void solve(){
	// code starts from here
	int N;
	cin >> N;
	vector<ll> vec(N);
	ll sum = 0;
	for(int i = 0; i < N; i++){
		cin >> vec[i];
		sum += vec[i];
	}
	sum %= MOD;
	ll ans = 0;
	
	for(int i = 0; i < N; i++){
		ans += (vec[i]*(sum-vec[i]));
		ans %= MOD;
		ans += MOD;
		ans %= MOD;
		
		sum -= vec[i];
		sum %= MOD;
		sum += MOD;
		sum %= MOD;
	}
	cout << ans << endl;
}

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

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


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

using pii = pair<int, int>;

int absolut(const int vodka){
	return max(vodka, -vodka); }

pii intersect(const pii a, const pii b){
	return pii { max(a.first, b.first), min(a.second, b.second) }; }

pii enlarge(const pii a){
	return pii { a.first - 1, a.second + 1 }; }

bool inside(const pii a, const int x){
	return a.first <= x && x <= a.second; }

constexpr pii universal { (int)-1e6 - 10, (int)1e6 + 10 };
constexpr int unknown = -1;

vector<vector<int>> vec;
vector<pii> good_intervals;

bool dfs(const int cur, const int prev){
	for(const auto next : vec[cur]){
		if(next == prev) continue;
		if(!dfs(next, cur)) return false;
		good_intervals[cur] = intersect(good_intervals[cur], enlarge(good_intervals[next])); }
	return good_intervals[cur].first <= good_intervals[cur].second; }

vector<int> rez;

bool build(const int cur, const int prev){
	for(const auto next : vec[cur]){
		if(next == prev) continue;
		if(inside(good_intervals[next], rez[cur]+1)){
			rez[next] = rez[cur] + 1; }
		else if(inside(good_intervals[next], rez[cur]-1)){
			rez[next] = rez[cur] - 1; }
		else return false;
		if(!build(next, cur)) return false; }
	return true; }

int main(){
	int n, k;
	cin >> n;
	vec.resize(n), good_intervals.resize(n, universal), rez.resize(n);
	for(int i = n-1, x, y; i; --i){
		cin >> x >> y;
		vec[--x].push_back(--y);
		vec[y].push_back(x); }

	cin >> k;

	int root = 0;
	for(int i = k, v, p; i; --i){
		cin >> v >> p;
		root = --v;
		rez[v] = p;
		good_intervals[v] = make_pair(p, p); }

	if(!dfs(root, -1) || !build(root, -1)){
		cout << "No\n";
		return 0; }

	cout << "Yes\n";
	for(const auto x : rez){
		cout << x << '\n'; }
	
	return 0; }

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

int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++){
        cin >> a.at(i);
    }

    int p = accumulate(a.begin(), a.end(),0);

    if(p>=22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64; 
long long const INF = 1e18 + 42;
 
 
int main(){
	fast;
	unordered_map<lli, int> mp;
	int n;
	cin>>n;
	bool flag=0;
	for(int i=0; i<n; i++){
	    lli x;
	    cin>>x;
	    mp[x]++;
	    if(mp[x]>1) flag=1;
	}
	if(flag) cout<<"NO";
	else cout<<"YES";
	return 0;
}

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

int A[1005][1005];
stack<int> st[1005];
int pushed[1005];

int main(void){
    int N; cin >> N;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < N-1; j++) {
            cin >> A[i][j];
        }
    }
    
    
    for (int i = 1; i <= N; i++) {
        for (int j = N-2; 0 <= j; j--) {
            st[i].push(A[i][j]);
        }
    }

    vector<int> v[2];
    for (int i = 1; i <= N; i++) {
        v[0].push_back(i);
    }
    
    int ans = 0;
    int flag = 1;
    while (flag) {
        flag = 0;
        int crtV = ans%2;
        int nextV = (ans+1)%2;
        while (!v[crtV].empty()) {
            int player = v[crtV].back();
            v[crtV].pop_back();
            if (st[player].empty()) continue;
            if (st[st[player].top()].empty()) continue;
            if (player == st[st[player].top()].top() && pushed[player] == 0) {
                flag = 1;
                v[nextV].push_back(player);
                v[nextV].push_back(st[player].top());
                pushed[player] = 1;
                pushed[st[player].top()] = 1;
            }
        }
        for (int i = 0; i < v[nextV].size(); i++) {
            int player = v[nextV][i];
            st[player].pop();
        }
        memset(pushed, 0, sizeof(pushed));
        crtV = nextV;
        if (flag) ans++;
    }
    for (int i = 1; i <= N; i++) {
        if (!st[i].empty()) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8576