akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

map<int, ll> M;
ll n, k;

ll pow(ll a, ll b) {
    ll r = 1;
    while(b > 0) {
        if(b % 2 == 1) r = (r * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return r;
}

int main() {
    cin >> n >> k;
    vector<int> dzielniki;
    for(int d = 1; d * d <= n; d++) {
        if(n % d == 0) {
            dzielniki.push_back(d);
            if(n / d != d) {
                dzielniki.push_back(n / d);
            }
        }
    }
    sort(dzielniki.begin(), dzielniki.end());
    for(int j = 0; j < dzielniki.size(); j++) {
        ll d = dzielniki[j];
//         cout << d << endl;
        M[d] = pow(k, (d + 1) / 2);
//         cout << "M[" << d << "] = " << M[d] << endl;
        for(int i = 0; i < dzielniki.size(); i++) {
            if(dzielniki[i] >= d) break;
            if(d % dzielniki[i] == 0) M[d] = (M[d] - M[dzielniki[i]] + MOD) % MOD;
        }
//         cout << "M[" << d << "] = " << M[d] << endl;
    }
    ll wynik = 0;
    for(ll d : dzielniki) {
        ll curr = 0;
        if(d % 2 == 1) {
            curr = (M[d] * d) % MOD;
        } else {
            curr = (M[d] * (d / 2LL)) % MOD;
        }
        wynik = (wynik + curr) % MOD;
    }
    cout << wynik;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int S;

	int h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S - h * 3600 - m * 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)


using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int> > s(M);
    for (int i = 0; i < M; ++i) {
        int k; cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; ++i) cin >> p[i];
    
    
    int ans = 0;
    for (int i = 0; i < (1 << N) ; ++i){
        bool ok = true;
        for (int ind = 0; ind < M; ++ind){
            int c = 0;
            for (int var: s[ind]){
                if ((i >> var) & 1)
                    ++c;
            }
            c %= 2;
            if ( c != p[ind])
                ok = false;
                
        }
        if ( ok)
            ++ans;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
1 1
)");
#define cin input
#endif

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

	int l = 0;
	int c = 0;
	int r = 0;
	REP (i, n)
	{
		int a;
		cin >> a;
		++c;
		if (l == a)
			continue;
		l = a;
		r += --c / 2;
		c = 1;
	}
	r += c / 2;

	cout << r << endl;

	return 0;
}


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

typedef long long ll;

int v[101],w[101];
ll dp[102][100002];

int main() {
  int N,W; cin >> N >> W;
  for ( int i = 0; i < N; i++ ) cin >> w[i] >> v[i];

  for ( int i = 0; i < N; i++ ) {
    for ( int j =  0; j  <= W; j++ ) {
      if ( w[i] > j ) dp[i+1][j] = dp[i][j];
      else if ( w[i] <= j ) {
	dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
      }
    }
  }
  /*
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j <= W; j++ ) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 78336
def water(flowers, count):
    if len(flowers) is 0:
        return count
    count = count + min(flowers)
    flowers = [int(e-min(flowers)) for e in flowers]
    while 0 in flowers:
        count = water(flowers[:flowers.index(0)], count)
        flowers = flowers[flowers.index(0)+1: ]
    count = water(flowers, count)
    return count

n = int(input())
flowers = [int(e) for e in input().split()]

count = 0
count = water(flowers, count)
print(count)

Measured memory_bytes: 3064
def main():
  import sys
  n,*d=map(int,sys.stdin.buffer.read().split())
  e=[0]*n
  
  for i in d:
    e[i]+=1
  
  a=e[0]
  
  for i in d[1:]:
    a=a*e[i-1]%998244353
    
  print(a)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 11628
#include<algorithm>
template<class T>
int mcm(T first, T last) {
    const auto N = std::distance(first, last) - 1;
    int dp[N][N];
    std::fill(dp[0], dp[N], 1 << 28);
    for (int i = 0; i < N; ++i) dp[i][i] = 0;
    for (int L = 1; L < N; ++L)
        for (int i = 0; i < N - L; ++i) {
            int j = i + L;
            for (int k = i; k < j; ++k)
                dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k + 1][j] + first[i] * first[k + 1] * first[j + 1]);
        }
    return dp[0][N - 1];
}
#include<iostream>
#include<vector>
using namespace std;
int main() {    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> vec(n+1);
    for(int i=0;i<n;++i) cin>>vec[i]>>vec[i+1];
    cout<<mcm(vec.begin(),vec.end())<<endl;
}

Measured memory_bytes: 3196
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        String S=sc.next();
        int n=S.length();
        for(int i=n-2;true;i-=2){
            String v=S.substring(0,i/2),u=S.substring(i/2,i);
            if(v.equals(u)){
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 35460
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL as(n);
  FOR(a,as) {
    cin >> a;
  }
  VL sum(n+1, 0);
  REP(i,0,n) {
    sum[i+1] = sum[i] + as[i];
  }
  sort(sum.begin(), sum.end());
  ll count = 0;
  ll same = 1;
  ll prev = 1e15;
  REP(i,0,n+1) {
    if(sum[i] == prev) {
      same++;
    } else {
      count += same * (same - 1) / 2;
      same = 1;
      prev = sum[i];
    }
  }
  count += same * (same - 1) / 2;
  cout << count << endl;
  
  return 0;
}


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


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long N;
	cin >> N;
	vector<long long> v;
	for(long long i = 1;i*i<=N;i++){
		if(N%i==0)v.push_back(i);
	}
	long long ans = 1e13;
	for(auto x:v){
		ans = min(ans,-2 + x + N/x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

// ------------------------------------------------------------------------------------------------

ll n;
vpll ab;

void func() {
    cin >> n;
    ab.resize(n);
    for (ll i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end(), [](pll &l, pll &r) -> bool {
        if (l.second != r.second) {
            return l.second < r.second;
        } else {
            return l.first < r.first;
        }
    });
    for (ll i = 0, t = 0; i < n; i++) {
        t += ab[i].first;
        if (t > ab[i].second) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] timeInfo = new int[n +1];
		for(int i =1;i <= n;i++) {
			timeInfo[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		for(int i = 0;i < m;i++) {
			int[] timeInfod = timeInfo.clone();
			timeInfod[sc.nextInt()] = sc.nextInt();
			int totalTime = 0;
			for(int time :timeInfod) {
				totalTime += time;
			}
			System.out.println(totalTime);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
typedef pair<int, int> P;

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

    ll m = n / k;
    ll sum = m*m*m;

    if (k % 2 == 0) {
        ll m2 = (n+k/2)/k;
        sum += m2*m2*m2;
    }
    
    cout << sum << endl;
    
}

Measured memory_bytes: 384
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0:
        print(" {0}".format(i), end="")
    else:
        x = i
        while x != 0:
            if x % 10 == 3:
                print(" {0}".format(i), end="")
                break;
            x //= 10;
print("")

Measured memory_bytes: 7992
#include <iostream>
using namespace std;
int main() {
    int a,n;
    cin>>a>>n;
    int arr[105]={0},x;
    //cout<<arr[50];
    for(int i=0;i<n;i++){
      cin>>x;
      arr[x]=1;
   }
   int ans=1001,res=1;
  for(int i=0;i<=105;i++)
   if(arr[i]==0&&ans>abs(i-a)){
       ans=abs(i-a);
       res=i;
   } 
   cout<<res;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
    boolean[] isPrime;
    void run(){
	isPrime = new boolean[1000001];
	for(int i=0;i<=1000000;i++) isPrime[i] = true;

	isPrime[0] = false;
 	isPrime[1] = false;
  
	for(int i=2;i<=1000000;i++){
	    if(!isPrime[i]) continue;
	    for(int j=i+i;j<=1000000;j+=i){
		isPrime[j] = false;
	    }
	}
	Scanner sc = new Scanner(System.in);
 
	while(sc.hasNext()){
	    int n=sc.nextInt();
	    int count = 0;
	    for(int i=0;i<=n;i++){
		if(isPrime[i]) count++;
	    }
	    System.out.println(count);
	}
    }
    public static void main(String[] args){
	new Main().run();
    }
}

Measured memory_bytes: 22420
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

typedef vector<vvi> vvvi;

int main() {
	int N, K;

	cin >> N >> K;
		vvvi dp(N+1, vvi(4, vi(4, 0)));
		map<int, int> info;

		REP(i, K) {
			int a, b;
			cin >> a >> b;
			info[a] = b;
		}

		if(info[1] && info[2]) {
			dp[2][info[1]][info[2]] = 1;
		} else if(info[1]) {
			FOR(i, 1, 3) {
				dp[2][info[1]][i] = 1;
			}
		} else if(info[2]) {
			FOR(i, 1, 3) {
				dp[2][i][info[2]] = 1;
			}
		} else {
		FOR(d, 1, 2) {
			FOR(i, 1, 3) {
				FOR(j, 1, 3) {
					dp[d][i][j] = 1;
				}
			}
		}
		}

		FOR(d, 3, N) {
			if(info[d]) {
				int tod = info[d];
				FOR(yes, 1, 3) {
					FOR(bef, 1, 3) {
						if(bef == yes && yes == tod) {

						} else {
							dp[d][yes][tod] += dp[d-1][bef][yes];
						}
					}
					dp[d][yes][tod] %= 10000;
				}
			} else {
				FOR(tod, 1, 3) {
					FOR(yes, 1, 3) {
						FOR(bef, 1, 3) {
							if(bef == yes && yes == tod) {

							} else {
								dp[d][yes][tod] += dp[d-1][bef][yes];
							}
						}
						dp[d][yes][tod] %= 10000;
					}
				}
			}
		}

		int ans = 0;
		FOR(i, 1, 3) {
			FOR(j, 1, 3) {
				ans += dp[N][i][j];
			}
		}

		cout << ans%10000 << endl;

	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,y;
	cin>>x>>y;
	int k=1;
	long long t=x;
	while(t*2<=y)
	{
		t*=2;
		++k;
	}
	cout<<k<<endl;
	return 0;
}

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

#define int long long
#define INF 9223372036854775807

int v[109][2];

int memo[100009][109];

int n, w;

int dp(int left, int index){
    if(index == n) return 0;
    if(memo[left][index] != -1) return memo[left][index];
    if(v[index][0] > left){
        return dp(left, index+1);
    }else{
        return memo[left][index] = max(dp(left-v[index][0], index+1)+v[index][1], dp(left, index+1));
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> w;
    for(int i = 0; i< n; i++){
        cin >> v[i][0] >> v[i][1];
    }
    for(int i = 0; i < 100009; i++){
        for(int j = 0; j < 109; j++){
            memo[i][j] = -1;
        }
    }
    cout << dp(w, 0) << endl;
}


Measured memory_bytes: 85376
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl
using namespace std;
int max_int = 2147483647;
int prime = 10e9+7;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;




signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    vec(a,n);
    vec(b,n)
    REP(i,n){
        cin >> b[i];
        a[i] = b[i]-i-1;
    }
    Sort(a);
    int t = a[n/2];
    int ans = 0;
    REP(i,n){
        ans += abs(b[i]-t-i-1);
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 3456
N = int(input())
A = [int(s)-1 for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]

total = 0
for i, Ai in enumerate(A):
  total += B[Ai]
  if i >= 1:
    if A[i] == A[i-1]+1:
      total += C[Ai-1]
print(total)

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

int main() {
    int N; cin >> N;
    vector<vector<ll>> v(2, vector<ll>(N+1,0));
    for (int i = 0; i < 2; i++){
        for (int j = 0; j <= N; j++){
            if(j==0) v[i][j] = 0;
            else{
                int a; cin >> a;
                v[i][j] = v[i][j-1] + a;
            } 
        } 
    }

    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans = max(ans, v[0][i] + (v[1][N] - v[1][i-1]));        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;

int i, j, k, tmp, ans, cnt, N;
string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;


int main(void) {
	int a, b;
	scanf("%d %d", &a ,&b);
	if (a >= 1 && a <= 9) {
		if (b >= 1 && b <= 9) {
			printf("%d",a*b);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

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

typedef long long ll;
ll n, m, g;
string a, b;
ll f(ll p, ll q) {
	if (p % q == 0) return q;
	f(q, p % q);
}
int main()
{
	ll i, j, k;
	cin >> n >> m;
	cin >> a;
	cin >> b;
	g = f(n, m);
	for (i = min(n, m); i >= 1; i--) {
		if (n % i == 0 && m % i == 0) {
			for (j = 0, k = 0; j < n; j += n / i, k += m / i) {
				if (a[j] != b[k]) break;
			}
			if (j >= n) {
				for (j = 0, k = 0; j < n; j += n / g, k += m / g) {
					if (a[j] != b[k]) break;
				}
				if (j >= n) {
					cout << n * m / i;
					return 0;
				}
			}
		}
	}
	cout << -1;
    return 0;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
p=[0]
p*=n
ac=set()
wa=0
for i in range(m):
    pi,si=input().split()
    pi=int(pi)
    if si=='AC' and not pi in ac:
        ac.add(pi) 
        wa+=p[pi-1]
    else:
        p[pi-1]+=1
ans=len(ac)
print(ans,wa,end=' ')



Measured memory_bytes: 18232
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N, M;
string S;

vector<int>E[404040];

int TopologicalSort(){
	vector<int>in;
	N *= 2;
	in.resize(N);
	for(int i = 0;i < N;i++)fore(x, E[i])in[x]++;

	stack<int>st;
	for (int i = 0; i < N; i++)if (!in[i])st.push(i);
	vector<int>li;
	while (st.size()) {
		int v = st.top();
		st.pop();
		li.pb(v);
		fore(x, E[v]) {
			in[x]--;
			if (!in[x])st.push(x);
		}
	}
	return li.size() != N;
}

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

	cin >> N >> M >> S;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (S[a] != S[b]) {
			E[a + N].pb(b);
			E[b + N].pb(a);
		}
		else {
			E[a].pb(b + N);
			E[b].pb(a + N);
		}
	}

	if (TopologicalSort())puts("Yes");
	else puts("No");

	return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i = 0; i < N; ++i) cin >> H[i];
  sort(H.rbegin(), H.rend());
  long long ans = 0;
  for(int i = K; i < N; ++i){
    ans += H[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int h, w;
  cin >> h >> w;
  string c;
  rep(i,h){
    cin >> c;
    rep(j,2){
      cout << c << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}
fn main(){
    let buf = &input_vec::<i32>();
    let a = buf.into_iter().position(|&r| r==0).unwrap();

    println!("{}",a+1);
}


Measured memory_bytes: 2076
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

def isOk(xor, val):
  while xor and val:
    if xor & 1 and val & 1:
      return False
    xor >>= 1
    val >>= 1
  return True
  
xor = 0
right = 0
ans = 0
for left in range(N):
  while right < N and isOk(xor, A[right]):
    xor ^= A[right]
    right += 1
  ans += right - left
  
  if left == right:
    right += 1
  else:
    xor ^= A[left]
    
print(ans)

Measured memory_bytes: 25636
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

struct DisjointSet {
	struct Node {
		int p, sz;
		Node(int p) : p(p), sz(1) {
		}
	};

	int N;
	vector<Node> v;

	DisjointSet(int N) : N(N) {
		for (int i = 0; i <= N; i++) {
			v.pb(Node(i));
		}
	}
	int find(int x) {
		if (v[x].p != x) {
			v[x].p = find(v[x].p);
		}
		return v[x].p;
	}
	void merge(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) {
			return;
		}

		if (v[x].sz > v[y].sz) {
			v[x].sz += v[y].sz;
			v[y].p = x;
		} else {
			v[y].sz += v[x].sz;
			v[x].p = y;
		}
	}
};

int N, A[305][305], B[305][305];
DisjointSet ds(305);
vector<pii> e;
ll cost;

bool c(pii x, pii y) {
    return A[x.x][x.y] < A[y.x][y.y];
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                if (A[i][k] > A[i][j] + A[j][k]) {
                    printf("-1\n");
                    return 0;
                }
            }
            e.pb(pii(i, j));
        }
    }
	sort(e.begin(), e.end(), c);

	for (int i = 0; i < e.size(); i++) {
        // Check if condition is already satisfied
        bool vis = 1;
        for (int j = 1; j <= N; j++) {
            if (j == e[i].x || j == e[i].y) continue;
            if (A[e[i].x][j] + A[j][e[i].y] == A[e[i].x][e[i].y]) {
                vis = 0;
            }
        }
        cost += vis * A[e[i].x][e[i].y];
    }
    
    printf("%lld\n", cost / 2);
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string O, E;

	cin >> O >> E;

	rep(i, (int)E.length()) cout << O[i] << E[i];
	if (O.length() != E.length()) cout << O[O.length() - 1];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
//typedef std::pair<int,int> P;

    ll N,ans=-INF;
    ll F[101][11];
    ll P[101][11];
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N)REP(j,10)cin>>F[i][j];
    REP(i,N)REP(j,11)cin>>P[i][j];
    REP(Bit,1<<10){
        ll res=0;
        if(Bit==0)continue;
        REP(i,N){
            int cnt=0;
            REP(j,10){
                if(((Bit>>j)&1)&&F[i][j]==1){
                    cnt++;
                }
            }

            res+=P[i][cnt];
        }
        ans=max(res,ans);
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,ans=0,cnt=0,x=inf;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    if(a<0) {
      cnt++;
    }
    ans+=abs(a);
    x=min(x,abs(a));
  }
  cout << (cnt%2?ans-=x*2:ans) << endl;
 }

Measured memory_bytes: 256
package main
import (
	"fmt"
	"math"
)
func main(){
	var n, m float64
	fmt.Scan(&n, &m)
	var s int
	s=int(m)
	a:=make([]int, s)
	for i:=0;i<s;i++{
		fmt.Scan(&a[i])
	}
	temp:=math.Ceil((n-1)/(m-1))
	fmt.Println(temp)
}


Measured memory_bytes: 5376
def nums():
    return list(map(int,input().split(" ")))
def num():
    return int(input())
def yakusu(n):
    res = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.add((i,int(n/i)))
    return res
"""
a,b = nums()
if a <= 9 and b <= 9:
    print(a * b)
else:
    print(-1)
"""
"""
n = num()
qq = []
for i in range(10):
    for j in range(10):
        qq.append(i * j)
if n in qq:
    print("Yes")
else:
    print("No")
"""
"""
N = num()
y = yakusu(N)

min = -1

for i in y:
    x,y = i
    if min == -1:
        min = x + y
    elif min > x + y:
        min = x+y

print(min-2)
"""

import math as m
a,b,x = nums()
t = a**2 * b
if (x < (t/2)):
    w = (x * 2) / (a*b)
    ans = m.atan(w/b)
    print(90 - m.degrees(ans))
else:
    yoyu = t - x
    yh = (yoyu *2 ) / a / a
    ans = m.atan(yh/a)
    print(m.degrees(ans))
#E
"""
N,K = nums()
As = nums()
As.sort(reverse=True)
Fs = nums()
Fs.sort(reverse=True)
costs = []
idx = 0
for f in Fs:
    print(f"K={K},F({idx})={f},A({idx})={As[idx]}")
    s_cost = As[idx]
    if f > K and K > 0:
        if s_cost >= K:
            s_cost -= K
            K = 0
        else:
            K -= s_cost
            s_cost = 0
        costs.append((f,s_cost))
    if K > 0:
        if s_cost >= K:
            s_cost -= K
            K -= f
        else:
            K -= s_cost
            s_cost = 0
            
        costs.append((f,s_cost))
    else:
        costs.append((f,s_cost))
    idx += 1
print("---")
res = []
for i in costs:
    c,s = i
    res.append(c*s)
    print(f"{c}x{s},",end="")
print(max(res))
"""

Measured memory_bytes: 38384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

n,x = map(int,input().split())
M = list(int(input()) for i in range(n))
ans = n
x -= sum(M)
M.sort()
ans += x//M[0]
print(ans)

Measured memory_bytes: 3316
#include <iostream>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  bool flag = false;
  if (a == b && a != c) flag = true;
  else if (a == c && a != b) flag = true;
  else if (b == c && b != a) flag = true;
  if (flag) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int main() {
	long long int n, a, b;
	long long  int ans;

	cin >> n >> a >> b;

	ans = a * (n / (a + b));

	if (n % (a + b) > a) {
		ans +=a;
	}
	else{
		ans += n % (a + b);
	}
	cout << ans << endl;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k,b;
  long long int ans=0;
  cin>>n>>k;
  if(k){
  for(b=k+1;b<=n;b++){
    ans+=(b-k)*(n/b);
    if(n%b>=k){
    ans+=(n%b)-k+1;
    }
  }
  cout<<ans<<endl;
  }else{
    cout<<n*n<<endl;
  }
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;cin>>n;
  for (int i = 1; i <= n; i*=2)
  {
  	if(i*2>n)cout<<i<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    vector<int>v(3);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    if((v[0]==v[1]&&v[1]!=v[2])||(v[0]!=v[1]&&v[1]==v[2])){
        cout << "Yes" << endl;
    }    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] k = new int[n];
		for(int i=0;i<n;i++) {
			k[i] = in.nextInt();
		}
		Stack<int[]> stack = new Stack<>();
		int[] start = new int[2];
		start[0] = 0;
		start[1] = n-1;
		stack.push(start);
		int ans = 0;
		while(!stack.isEmpty()) {
			int[] tmp = stack.pop();
			int idx_l = tmp[0];
			int idx_r = tmp[1];
			int min = Integer.MAX_VALUE;
			int min_idx = -1;
			for(int i=idx_l;i<=idx_r;i++) {
				if(k[i]<min) {
					min = k[i];
					min_idx = i;
				}
			}
			ans += min;
			for(int i=idx_l;i<=idx_r;i++) {
				k[i] -= min;
			}
			if(idx_l<=min_idx-1) {
				int[] left = new int[2];
				left[0] = idx_l;
				left[1] = min_idx-1;
				stack.push(left);
			}
			if(min_idx+1<=idx_r) {
				int[] right = new int[2];
				right[0] = min_idx+1;
				right[1] = idx_r;
				stack.push(right);
			}	
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 23636
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;

int n, m;
string tmp;
map<string, int> mp;

int main(){
  cin >> n;
  REP(i, n){
    cin >> tmp;
    auto itr = mp.find(tmp);
    if(itr != mp.end()){
      ++mp[tmp];
    } else {
      mp[tmp] = 1;
    }
  }

  cin >> m;
  REP(i, m){
    cin >> tmp;
    auto itr = mp.find(tmp);
    if(itr != mp.end()){
      --mp[tmp];
    }
  }

  int ans = 0;
  for(auto itr = mp.begin();itr!=mp.end();++itr){
    if(itr->second > ans){
      ans = itr->second;
    }
  }

  cout << ans << endl;

  return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse=1)
q.sort(reverse=1)
r.sort(reverse=1)
r = list(accumulate(r))
ans = 0
h = []
s = sum(p[:x])
s += sum(q[:y])
for i in p[:x]:
    heappush(h, i)
for i in q[:y]:
    heappush(h, i)
ans = s
for i in range(c):
    if len(h) > 0:
        f = heappop(h)
    else:
        break
    s -= f
    tmp = s + r[i]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 105324
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
t = reads()
v = reads()
psumt = [0] + list(accumulate(t))
T = psumt[-1]

vs = [0] * (T+1)
ans = 0
for ss in range(0, 2 * T):
  s = ss / 2
  m = min(
    abs(s),
    min(v[i] + (abs(psumt[i] - s) + abs(psumt[i+1] - s) - t[i]) / 2 for i in range(N)),
    abs(T-s)
  )
  ans += m / 2
print('%.9f' % ans)

Measured memory_bytes: 42844
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>

using ll = long long;

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int n, a, b;

int digSum(int num)
{
    string s = to_string(num);
    
    int ret = 0;
    
    for (int i = 0; i < s.size(); i++) ret += (s[i]-48);

    return ret;
}

int main()
{
    
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> a >> b;
    
    int ret = 0;
    
    for (int i = 1; i <= n; i++)
    {
        int sz = digSum(i);
        if (sz >= a && sz <= b) ret += i;
    }
    
    cout << ret << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n, a;
    cin >> n >> a;
    if (n % 500 <= a) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
struct E{
	int to, nxt;
}e[maxn << 1];
int head[maxn], tot = 0;
void addedge(int u, int v){
	e[++tot].to = v, e[tot].nxt = head[u];
	head[u] = tot;
}
int s[maxn], dep[maxn], f[maxn]; int cu, cv;
void dfs(int cur, int fa){
	dep[cur] = dep[fa] + 1;
	f[cur] = fa;
	if (dep[cur] & 1) s[cur] = 1;
	else s[cur] = -1;
	for (int i = head[cur]; i; i = e[i].nxt){
		int v = e[i].to;
		if (v != fa){
			if (dep[v]){
				if (cu == 0) cu = cur, cv = v;
			}
			else dfs(v, cur), s[cur] += s[v];
		}
	}
}
int n, m;
int abs(int x){return x < 0 ? -x : x;}
void work1(){
	if (s[1] != 0){puts("-1"); exit(0);}
	int ans = 0;
	for (int i = 1; i <= n; i++) ans += abs(s[i]);
	printf("%d\n", ans); exit(0);
}
void work2(){
	if (s[1] % 2 != 0){puts("-1"); exit(0);}
	int t = -s[1] / 2;
	int ans = abs(t);
	for (; cu; cu = f[cu]) s[cu] += t;
	for (; cv; cv = f[cv]) s[cv] += t;
	for (int i = 1; i <= n; i++) ans += abs(s[i]);
	printf("%d\n", ans); exit(0);
}
vector <int> v;
void work3(){
	if (s[1] != 0){puts("-1"); exit(0);}
	for (; cu != cv; cu = f[cu]) dep[cu] = 0, v.push_back(s[cu]);
	sort(v.begin(), v.end());
	int mid = v[(v.size() - 1) / 2];
	int ans = abs(mid);
	for (int i = 1; i <= n; i++)
		if (dep[i] != 0) ans += abs(s[i]);
		else ans += abs(s[i] - mid);
	printf("%d\n", ans); exit(0);
}
int main(){
	scanf("%d%d", &n, &m);
	for (int u, v, i = 1; i <= m; i++){
		scanf("%d%d", &u, &v);
		addedge(u, v); addedge(v, u);
	} dfs(1, 0);
	if (m == n - 1) work1();
	if ((dep[cu] - dep[cv]) % 2 == 0) work2();
	work3();
	return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll H,W,n;
  cin >> H >> W >> n;
  VLL x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];
  // x,y座標においてマンハッタン距離が最小になるように独立に考える
  VLL xx(x), yy(y);
  sort(all(xx));
  sort(all(yy));
  VLL midX = { xx[(n-1)/2] , xx[n/2]};
  VLL midY = { yy[(n-1)/2] , yy[n/2]};
  ll ans = LONG_MAX;
  ll ansx, ansy;
  for(ll mx :midX) for(ll my: midY){
    ll tmp = 0, maxDist = 0;
    rep(i,n){
      maxDist = max(maxDist, abs(mx - x[i]) + abs(my - y[i]) );
      tmp += 2LL * (abs(mx - x[i]) + abs(my - y[i]));
    }

    if( (tmp - maxDist) < ans){
      ans = tmp - maxDist;
      ansx = mx, ansy = my;
    }
  }

  cout << ans << endl;
  cout << ansx << " " << ansy << endl;
  return 0;
}



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

int main(){
  int i;
  int N,Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> a(N);//S[0]からS[i]までで何個あるか
  for(i=1;i<N;i++){
    if(S[i-1] == 'A' && S[i] == 'C') a[i] = a[i-1]+1;
    else a[i] = a[i-1];
    //cout << i << " " << a[i] << endl;
  }
  int l,r;
  for(i=0;i<Q;i++){
    cin >> l >> r;
    cout << a[r-1] - a[l-1] << endl;
  }
  return 0;
}
    
  

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

long long n,a,m,k,q,b,c=1;
string ss,s1,s2;
int main(){
    cin>>a>>b;
    if ((a+b)%2==1){
        cout<<"IMPOSSIBLE"<<endl;
    }
    else{
        cout<<(a+b)/2<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int n,m,a;

int G[1001][101];

int main(void){
	while(1){
		scanf("%d %d %d",&n,&m,&a);
		if(n+m+a==0)break;
		memset(G,0,sizeof(G));
		for(int i=0;i<m;i++){
			int h,p,q;
			scanf("%d %d %d",&h,&p,&q);
			G[h][p]=q;
			G[h][q]=p;
		}
		for(int i=1000;i>=0;i--){
			if(G[i][a]!=0)a=G[i][a];
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 1428
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
        }
        System.out.println(Arrays.stream(h).boxed().sorted(Comparator.reverseOrder()).skip(k).mapToLong(l -> l).sum());
    }
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) cout << "a > b" << endl;
    else if (a == b) cout << "a == b" << endl;
    else cout << "a < b" << endl;
}



Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#define N 20
#define Q 200

int n,A[N];

int judge(int i, int x){
    if(x == 0)return 1;
    if(i >= n)return 0;
    int res = judge(i + 1, x) || judge(i + 1, x - A[i]);
    return res;
}

int main(){
    int q , Mi , i;

    scanf("%d",&n);
    for(i = 0 ; i < n ; i++){
        scanf("%d",&A[i]);
        if(A[i] < 1 || A[i] > 2000)exit(1);
    }
    scanf("%d",&q);
    for(i = 0 ; i < q ; i++){
        scanf("%d",&Mi);
        if(Mi < 1 || Mi > 2000)exit(1);
        if(judge(0,Mi))printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



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

using namespace std;

int a[2][105];
int dp[2][105];


int main() {

	int n;
	cin >> n;
	for(int i=0;i<2;i++)
		for(int j=0;j<n;j++)
			cin >> a[i][j];
	dp[0][0] = a[0][0];
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			if(i!=0 and j!=0){
				dp[i][j] = a[i][j]+max(dp[i-1][j],dp[i][j-1]);
			}else if(j!=0){
				dp[i][j] = a[i][j]+dp[i][j-1];
			}else if(i!=0){
				dp[i][j] = a[i][j]+dp[i-1][j];
			}
		}
	}

	cout << dp[1][n-1];


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int N, M;
    cin >> N >> M;
    set<pii> Set;
    for (int m = 0; m < M; ++m) {
        int a, b;
        cin >> a >> b;
        Set.insert({b, a});
    }
    
    int Res = 0;
    int Last = 0;
    for (auto it = Set.begin(); it != Set.end(); ++it) {
        pii Tmp = *it;
        if (Tmp.second > Last) {
            Last = Tmp.first - 1;
            ++Res;
        }
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 4992
import fractions
N = int(input())
A = list(map(int,input().split()))

a = A[0]
for i in range(1, N):
    a = a * A[i] // fractions.gcd(a, A[i])
saikou = a

A = [saikou * 1.0 / i for i in A]
print(1.0 * saikou / sum(A))


Measured memory_bytes: 5600
using System;

class Program {
    static void Main() {
        var q = int.Parse(Console.ReadLine());
        for (var i = 0; i < q; i++) {
            var l = Console.ReadLine().Split(' ');
            var c = int.Parse(l[0]);
            var a = int.Parse(l[1]);
            var n = int.Parse(l[2]);

            Console.WriteLine(GetTeamCount(c, a, n));
        }
    }

    static int GetTeamCount(int c, int a, int n) {
        var count = 0;
        {
            var x = Math.Min(c, Math.Min(a, n));
            count += x;
            c -= x;
            a -= x;
        }
        {
            var x = Math.Min(c / 2, a);
            count += x;
            c -= x * 2;
        }
        count += c / 3;

        return count;
    }
}

Measured memory_bytes: 9172
N,K=map(int,input().split())
mod=10**9+7
c=[1]
for i in range(1,N+1):
  c+=[c[i-1]*i]

def cmb(a,b):
  return c[a]//c[a-b]//c[b]
  
for i in range(1,K+1):
  if N-K<i-1 or K<i:
    print(0);continue
  
  m=cmb(K-1,i-1)%mod
  n=cmb(N-K+1,i)%mod
  ans=m*n%mod
  print(ans)

Measured memory_bytes: 44144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        String[] list = new String[n];
        int count = 1;
        int max = 1;
        List<String> ans = new ArrayList<String>();
        for(int i = 0; i < n ; i++){
            list[i] = input.readLine();
        }
        Arrays.sort(list);
        for(int j = 0; j < n ; j++){
            if(j > 0){
                if (list[j].equals(list[j-1])){
                    count++;
                }else{
                    count = 1;
                }
            }
            if(max < count){
                max = count;
            }
        }
        Arrays.sort(list);
        count = 1;
        for(int k = 0; k < n ; k++){
            if(k > 0){
                if (list[k].equals(list[k-1])){
                    count++;
                }else{
                    count = 1;
                }
            }
            if(max == count){
                ans.add(list[k]);
            }
        }
        for(int l = 0; l < ans.size(); l++){
        System.out.println(ans.get(l));
        }

    }
}

Measured memory_bytes: 58580
n,m,x=gets.split.map &:to_i
cas=$<.read.split.map(&:to_i).each_slice(m+1).to_a
ar=(0...2**n).map{|e|
  csum=0
  as=[0]*m
  n.times{|i|
    e[i]>0 or next
    r=cas[i]
    csum+=r[0]
    m.times{|j|
      as[j]+=r[j+1]
    }
  }
  [csum,as.all?{|a| a>=x }]
}.select{|r| r[1] }.min
puts ar ? ar[0] : -1



Measured memory_bytes: 14468