akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>

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

using namespace std;

pair<int,int> searchMaxValue(vector<int> v){
    int count = 1;
    int cMax = 1;
    if(v.size() == 0) return make_pair(0,0);
    int nMax = v[0];
    int tmp = v[0];

    for(int i = 1; i < v.size(); i++){
        if(tmp == v[i]){
            count++;
            if(cMax < count) {
                cMax = count;
                nMax = v[i];
            }
        }else{
            tmp = v[i];
            count = 1;
        }
    }
    return make_pair(cMax,nMax);
};



int main() {
    int n;
    cin >>  n;
    vector<int> even;
    vector<int> odd;
    rep(i, n){
        int tmp;
        cin >> tmp;
        if(i % 2 == 0){
            even.pb(tmp);
        }else{
            odd.pb(tmp);
        }
    }
    sort(even.begin(),even.end());
    sort(odd.begin(),odd.end());

    pair<int,int> evenAns = searchMaxValue(even);
    pair<int,int> oddAns = searchMaxValue(odd);

    if(evenAns.second != oddAns.second){
        cout << even.size() - evenAns.first + odd.size() - oddAns.first;
    }else{
        auto it1 = lower_bound(even.begin(),even.end(),evenAns.second);
        even.erase(it1,it1+evenAns.first);
        auto it2 = lower_bound(odd.begin(),odd.end(),oddAns.second);
        odd.erase(it2,it2+oddAns.first);
        pair<int,int> eSecondAns = searchMaxValue(even);
        pair<int,int> oSecondAns = searchMaxValue(odd);
        even.resize(even.size() + evenAns.first);
        odd.resize(odd.size() + oddAns.first);
        if(eSecondAns.first > oSecondAns.first){
            cout << even.size() - eSecondAns.first + odd.size() - oddAns.first;
        }else{
            cout << even.size() - evenAns.first + odd.size() - oSecondAns.first;
        }
    }


    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<std::vector<int>> cntB(2 * K + 1, std::vector<int>(2 * K + 1, 0));
  std::vector<std::vector<int>> cntW(2 * K + 1, std::vector<int>(2 * K + 1, 0));
  for (int i = 0; i < N; ++i) {
    int x, y;
    char c;
    std::cin >> x >> y >> c;
    if (c == 'B') {
      ++cntB[x % (2 * K) + 1][y % (2 * K) + 1];
    } else {
      ++cntW[x % (2 * K) + 1][y % (2 * K) + 1];
    }
  }
  for (int i = 0; i <= 2 * K; ++i) {
    for (int j = 0; j + 1 <= 2 * K; ++j) {
      cntB[i][j + 1] += cntB[i][j];
      cntW[i][j + 1] += cntW[i][j];
    }
  }
  for (int i = 0; i + 1 <= 2 * K; ++i) {
    for (int j = 0; j <= 2 * K; ++j) {
      cntB[i + 1][j] += cntB[i][j];
      cntW[i + 1][j] += cntW[i][j];
    }
  }
  // K^2 個のstart positionについてその正方形に含まれる数を数えたい
  int ans = 0;
  auto allB = cntB[K * 2][K * 2];
  auto allW = cntW[K * 2][K * 2];
  auto get_squareB = [&](unsigned l, unsigned r, unsigned t, unsigned b) -> int {
    return cntB[r][b] + cntB[l][t] - cntB[l][b] - cntB[r][t];
  };
  auto get_squareW = [&](unsigned l, unsigned r, unsigned t, unsigned b) -> int {
    return cntW[r][b] + cntW[l][t] - cntW[l][b] - cntW[r][t];
  };
  for (int i = 0; i < K; ++i) {
    for (int j = 0; j < K; ++j) {
      auto pointB = get_squareB(i, i + K, 0, j) + get_squareB(0, i, j, j + K)
          + get_squareB(i, i + K, j + K, 2 * K) + get_squareB(i + K, 2 * K, j, j + K);
      auto pointW = get_squareW(i, i + K, 0, j) + get_squareW(0, i, j, j + K)
          + get_squareW(i, i + K, j + K, 2 * K) + get_squareW(i + K, 2 * K, j, j + K);
      ans = std::max({ans, pointB + allW - pointW, pointW + allB - pointB});
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N, X, a[102];

int main() {
  scanf("%d%d", &N, &X);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  sort(a + 1, a + N + 1);
  int Ans = 0;
  while (Ans + 1 <= N && X >= a[Ans + 1]) X -= a[++Ans];
  if (Ans == N) Ans -= X > 0;
  printf("%d\n", Ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long double a;
    long double ans = 0;
    rep(i,n){
        cin >> a;
        ans+=(1/a);
    }
    cout << setprecision(15) << 1/ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int arr[3];int cnt1=0;int cnt2=0;
  for(int i=0;i<3;i++)
    scanf("%d",&arr[i]);
  for(int i=0;i<3;i++)
  {
    if(arr[i]==5)
      cnt1++;
    else if(arr[i]==7)
      cnt2++;
  }
  if(cnt1==2&&cnt2==1)
   printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

Measured memory_bytes: 384
a, b, h, m = map(int, input().split())
from math import cos,sin, sqrt, radians

x_a = - a * cos(radians(360/12.0*h+360/12/60*m))
y_a = a * sin(radians(360/12.0*h+360/12/60*m))
x_b = - b * cos(radians(360/60.0*m))
y_b = b * sin(radians(360/60.0*m))

print(sqrt((x_a-x_b)**2+(y_a-y_b)**2))

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

int main(){
    int x, y;
    cin >> x >> y;

    int y_sum = 2*x;

    for(int i=0; i<=x; i++){
        if(y_sum==y){
            cout << "Yes" << endl;
            return 0;
        }
        y_sum += 2;
    }


    cout << "No" << endl;
}


Measured memory_bytes: 3636
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define int          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005
string s[N];
ll n,m,cnt,cnt1,vis[404][404],dp[404][404],ans;
ll dfs(ll i,ll j,ll f){
	vis[i][j]=1;dp[i][j]=1;
	for(int ii=-1;ii<=1;ii++){
		for(int jj=-1;jj<=1;jj++){
			if((ii==0&&jj==0)||(ii!=0&&jj!=0))continue;
			if((i+ii)<=0||(j+jj)<=0||(j+jj)>m||(i+ii)>n||vis[i+ii][j+jj])continue;
			if(s[i+ii][j+jj]=='#'&&f==1){
				dfs(i+ii,j+jj,0);cnt++;
			}else
			if(s[i+ii][j+jj]=='.'&&f==0){
				dfs(i+ii,j+jj,1);cnt1++;
			}
		}
	}
}
signed main()
{
	ios
	ll i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>s[i];
		s[i]=" "+s[i];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(s[i][j]=='#'&&!vis[i][j]){
				cnt=1,cnt1=0;
				dfs(i,j,0);
				ans+=cnt*cnt1;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long

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



long gcd(long a, long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

long A, B;

int main(){
	cin >> A >> B;
	long ans = lcm(A, B);
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)n; i++)
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int k=0;
  rep(i, n) if(p[i] != i + 1) k++; 
  if(k <= 2) cout << "YES" << endl; 
  else cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
   cin>>N;
   vector<int> A(N+1),B(N);
   for(int i=0;i<N+1;i++){
      cin>>A.at(i);
   }
   for(int i=0;i<N;i++){
      cin>>B.at(i);
   }

   int64_t count=0;
   for(int i=0;i<N;i++){
      if(A.at(i)>=B.at(i)){
         count+=B.at(i);
      }
      else{
         if(A.at(i+1)>=B.at(i)-A.at(i)){
            A.at(i+1)-=(B.at(i)-A.at(i));
            count+=B.at(i);
         }
         else{
            count+=A.at(i)+A.at(i+1);
            A.at(i+1)=0;
         }
      }
   }
   cout<<count<<endl;
}

Measured memory_bytes: 1024
import Control.Applicative
import Data.List
main =
    zipWith id [h,m,s] . repeat <$> readLn
    >>= putStrLn . (intercalate ":") . map show
    where
    h x = x `div` 3600
    m x = x `mod` 3600 `div` 60
    s x = x `mod` 3600 `mod` 60

Measured memory_bytes: 3628
import java.util.*;
import java.awt.geom.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			StringBuilder s = new StringBuilder(sc.next());
			for(int i = 0; i < s.length(); i++){
				int ind = s.charAt(i) - 'A';
				int newind = (ind - 3 + 26) % 26;
				s.setCharAt(i, (char)(newind + 'A'));
			}
			
			System.out.println(s.toString());
		}
	}

	
	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 17132
#include<iostream>
using namespace std;
#define KMAX 30
#define VMAX 1000000

int K[KMAX], T[VMAX+1];

void eratos ( int n, bool prime[]){
    for ( int i = 0; i <= n; i++ ) prime[i] = false;
    for ( int i = 3; i <= n; i += 2 ) prime[i] = true;
    prime[2] = true;
    for ( int i = 3; i*i <= n; i += 2 ){
	if ( !prime[i] ) continue;
	for ( int j = i + i; j <= n; j += i ) prime[j] = false;
    }
}

main(){
    bool prime[VMAX + 1];
    eratos( VMAX, prime );

    int k, v;
    while( cin >> k >> v && k && v ){
	for ( int i = 0; i < k; i++ ) cin >> K[i];
	
	for ( int j = 0; j <= v; j++ ) T[j] = 0;
	for ( int j = K[0]; j <= v; j += K[0] ) T[j] = 1;
	T[0] = 1;
	for ( int i = 1; i < k; i++ ){
	    for ( int j = K[i]; j <= v; j++ ){
		T[j] = (T[j] | T[j-K[i]]);
	    }
	}
	int ans = -1;
	for ( int i = v; i >= 2; i-- ){
	    if ( prime[i] && T[i] ) { ans = i; break; }
	}
	
	if ( ans == -1 ) cout << "NA" << endl;
	else cout << ans << endl;
    }
}

Measured memory_bytes: 5744
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;

inline int read() {
	int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
}

const int N = 200005;
int a[N];
LL f[N][5];

int main() {
	int n = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	for (int i = 1; i <= n; ++i) {
		f[i][0] = f[i - 1][0];
		for (int j = 1; j <= 4; ++j) f[i][j] = min(f[i - 1][j], f[i][j - 1]);
		f[i][0] += a[i];
		f[i][1] += (a[i] == 0) ? 2 : (a[i] & 1);
		f[i][2] += !(a[i] & 1);
		f[i][3] += (a[i] == 0) ? 2 : (a[i] & 1);
		f[i][4] += a[i];
	}
	LL ans = f[n][0];
	for (int i = 1; i <= 4; ++i) ans = min(ans, f[n][i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(n>1)
    n=((n)*(n-1))/2;
    else
    n=0;
    if(m>1)
    m=((m)*(m-1))/2;
    else
    m=0;
    cout<<n+m;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

string t;

int main() {
    cin >> t;
    int tlen = t.length();
    for(int i = 0; i < tlen; ++i) {
        if(t.at(i) == '?') t.at(i) = 'D';
    }
    cout << t << endl;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int dp[101][4][4][4];

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

  constexpr int mod = 1000000007;
  dp[0][3][3][3] = 1;
  for (int len = 0; len < n; ++len) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          if (dp[len][i][j][k] == 0) continue;

          for (int a = 0; a < 4; a++) {
            if (j == 0 && k == 1 && a == 2) continue;
            if (j == 1 && k == 0 && a == 2) continue;
            if (j == 0 && k == 2 && a == 1) continue;
            if (i == 0 && k == 1 && a == 2) continue;
            if (i == 0 && j == 1 && a == 2) continue;

            dp[len + 1][j][k][a] += dp[len][i][j][k];
            dp[len + 1][j][k][a] %= mod;
          }
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ans += dp[n][i][j][k];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;

  return 0; 
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 2000001
#define V 10000

int main()
{
    int a,n,i,j,cnt = 0;
    int A[V],B[V];

    scanf("%d",&n);
    if(n < 1 || n > N)exit(1);

    for(i = 0 ; i < V ; i++){
        A[i] = 0;
    }
    for(i = 0 ; i < n ; i++){
        scanf("%d",&a);
        A[a]++;
    }
    for(i = 0 ; i < V ; i++){
        for(j = 0 ; j < A[i] ; j++){
            printf("%d",i);
            if(cnt < n-1){
                printf(" ");
                cnt++;
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC083B
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = line1[0];
            int A = line1[1];
            int B = line1[2];

            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                int sum = i.ToString().ToCharArray().Select(x => x.ToString()).Select(int.Parse).ToArray().Sum();
                if (A <= sum && sum <= B) ans += i;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 17488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a[100010],b[100010];
	cin>>n;
	n++;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<n-1;i++){
		cin>>b[i];
	}
	b[n-1]=0;
	ll zan=0;
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll now=a[i];
		ans+=min(zan,a[i]);
		a[i]=max(ll(0),a[i]-zan);
		ans+=min(b[i],a[i]);
		zan=max(ll(0),b[i]-a[i]);
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

int a[1000010];

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

	scanf("%d", &n);
	n--;
	for(i=1; i<=n; i++)
	{
		for(j=i; j<=n; j+=i) a[j]++;
	}
	int res=0;
	for(i=1; i<=n; i++) res+=a[i];

	printf("%d\n", res);



	return 0;
}

Measured memory_bytes: 7604
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        list.add(sc.nextInt());
        list.add(sc.nextInt());
        list.add(sc.nextInt());

        Collections.sort(list);
        System.out.println(list.get(2) - list.get(0));
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a >= 13)
    printf("%d\n", b);
  else if (a >= 6)
    printf("%d\n", b / 2);
  else
    printf("0\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    k--;
    cout << a[k] << endl;
}


Measured memory_bytes: 3612
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    W, H, x, y = il()
    print((W * H) / 2, 1 if W / 2 == x and H / 2 == y else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10104
import java.util.Scanner;

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

        if("A".equals(str.substring(0,1))){
            int num =0;
            String str2 = str.substring(2,size-1);
            int size2 = str2.length();
            for(int i=0;i<size2;i++){
                String str4 = str2.substring(0,1);
                if(str4.equals("C")){
                    num = num+1;
                }
                str2 = str2.substring(1);
            }
            if(num==1){
                str2 = str.substring(2,size-1);
                str2 = str2.replace("C","c");
                str2 = str2.concat(str.substring(str.length() -1));
                str2 = str.substring(1,2).concat(str2);
                String str3 = str2.toLowerCase();

                if(str2.equals(str3)){
                    System.out.println("AC");
                }else{
                    System.out.println("WA"); 
                }

            }else{
                System.out.println("WA");    
            }
        }else{
            System.out.println("WA");
        }
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
const int MAX = 300005;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}

//check modulo
int main(){
	IOS;
	cout.precision(50) ;
	ll x , y  ;cin >> x >> y ;
	int nb = 1 ;
	while(log2(2) + log2(x) <= 63 && 2 * x <= y){
		nb++ ;
		x *= 2 ;
	}
	cout << nb << endl; 
	
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 1000000000;
const int mod = 1234567;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
long long k, s, sz;
int A[200005], p[200005];
int Vis[200005];

void Solve()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int temp = 1;
	Vis[1] = true;
	sz = 1;
	p[1] = 1;
	Vis[1] = 1;
	while(true)
	{
		temp = A[temp];
		if(Vis[temp])
		{
			s = Vis[temp];
			break;
		}
		sz++;
		p[sz] = temp;
		Vis[temp] = sz;
	}
	k++;
	if(k < s)
	{
		cout << p[k];
		return;
	}
	k -= s;
	//sz - s + 1
	k %= (sz - s + 1);
	cout << p[k + s];
}

signed main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 5948
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Scanner;
public class Main {
	public static void main( String[] args ) {
		Scanner sc = new Scanner( System.in ) ;
		String line = sc.nextLine();
		Pattern ptn = Pattern.compile( "^([0-9]+)\\s([0-9]+)$" ) ;
		Matcher mch = ptn.matcher( line );
		if ( mch.find() == true ) {
			int i = Integer.parseInt( mch.group(1) ) ;
			int j = Integer.parseInt( mch.group(2) ) ;
			System.out.println( i*j + " " + (2*i + 2*j) ) ;
		}
	}
}

Measured memory_bytes: 17128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll> 
#define vv vector<v>
#define p pair<ll,ll>
#define arrayinput int n; int m; cin>>n>>m; v arr (n+1,-1); for (int i=0; i<n; i++){int temp; cin>>temp;arr[i]=temp;}
#define vp vector<pair<int,p> >
int n;
int combine1(int a,int b)
{
    return min(a,b);
}
void update1(int pos,int value,v &tree)
{
    pos+=n-1;
    tree[pos]=value;
    pos=pos/2;
    while (pos>=1)
    {
        tree[pos]=combine1(tree[2*pos],tree[2*pos+1]);
        pos=pos/2;
    }
}
int query1(int l,int r, v&tree)
{
    l+=n-1;
    r+=n-1;
    ll ans=1e9;
    while (l<=r)
    {
        if (l%2==1)
        {
            ans=combine1(ans,tree[l]);
            l++;
        }
        if (r%2==0)
        {
            ans=combine1(ans,tree[r]);
            r--;
        }
        l=l/2;
        r=r/2;
    }
    return ans;
}


int combine2(int a,int b)
{
    return max(a,b);
}
void update2(int pos,int value,v &tree)
{
    pos+=n-1;
    tree[pos]=value;
    pos=pos/2;
    while (pos>=1)
    {
        tree[pos]=combine2(tree[2*pos],tree[2*pos+1]);
        pos=pos/2;
    }
}
int query2(int l,int r, v&tree)
{
    l+=n-1;
    r+=n-1;
    ll ans=-1e9;
    while (l<=r)
    {
        if (l%2==1)
        {
            ans=combine2(ans,tree[l]);
            l++;
        }
        if (r%2==0)
        {
            ans=combine2(ans,tree[r]);
            r--;
        }
        l=l/2;
        r=r/2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>n>>k;
    int ans=1;
    v arr(n+1);
    v tree1(2*n+10,0);
    v tree2(2*n+10,0);
    for (int i=1; i<=n; i++)
    {
    	cin>>arr[i];
    	update1(i,arr[i],tree1);
    	update2(i,arr[i],tree2);
    }


    v previuos(n+1,0);
    stack<int> stk;
    for (int i=n; i>=1; i--)
    {
        while (!stk.empty() && arr[i]>arr[stk.top()])
        {
            previuos[stk.top()]=i;
            stk.pop();
        }
        stk.push(i);
    }
    v tree3(2*n+10);
    for (int i=1; i<=n; i++)
    {
        update2(i,previuos[i],tree3);
    }
    // cout<<query1(2,4,tree1)<<endl;;
    int counter=0;  
    for (int i=k+1; i<=n; i++)
    {
        if (query2(i-k+1,i,tree3)<=i-k)
        {
            counter++;
            if (counter>=2)
                continue;
        }
    	if (query2(i-k+1,i,tree2)==arr[i] && query1(i-k,i-1,tree1)==arr[i-k])
    		continue;
    	ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 13568
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
#print(A)
A =[-a for a in A]
#print(A)
heapq.heapify(A)

for w in range(M):
    max=heapq.heappop(A)
    heapq.heappush(A,max/2)
   
B=list(map(int, A))
#print(B)
print(sum(B)*-1)

Measured memory_bytes: 99608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
char ch[11010];
int main(){
    cin>>ch;
    int len=strlen(ch);
    if(ch[len-1]=='s') printf("%ses",ch);
    else printf("%ss",ch);
    return 0;
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;


class MainClass
{
	public static void Main (string[] args)
	{
		List<int> mountain = new List<int>();
		for (int i = 1; i < 11; i++) {
			mountain.Add(int.Parse(Console.ReadLine()));
		}
		mountain.Sort();
		mountain.ToArray();
		for (int i = 1; i < 4; i++) {
			Console.WriteLine(mountain [10 - i]);
		}	
		Console.Read();
	}
}

Measured memory_bytes: 9044
#include<stdio.h>

#define MAX 100

int main(){
  int i,j,n,M[MAX][MAX],l,u,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&l);
      M[u-1][l-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",M[i][j]);
      if(j<n-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

      
    



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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll a, b,c;
	cin >>a >>b >>c;
	if (b*c>=a) cout <<"Yes";
	else cout <<"No";
	return 0; 
}
/******************************************************************************
******************************************************************************/


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

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

int main() {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    int i = 0;
    ll ans = 0;
    bool isStraight = false;
    if(s1[0] == s2[0]) {
        ans = 3;
        isStraight = true;
        i += 1;
    } else {
        ans = 6;
        isStraight = false;
        i += 2;
    }

    while(i < n) {
        if(s1[i] == s2[i]) {
            if (isStraight) {
                ans *= 2;
                ans %= MOD;
                isStraight = true;
            } else {
                isStraight = true;
            }
            i += 1;
        } else {
            if (isStraight) {
                ans *= 2;
                ans %= MOD;
                isStraight = false;
            } else {
                ans *= 3;
                ans %= MOD;
                isStraight = false;
            }
            i += 2;
        }
    }

    cout << ans << endl;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



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

    int m = 0;

    REP(i, n+1){
        if(i*(i+1)/2 >= n){
            m = i;
            break;
        }
    }

    RREP(i, m+1){
        if(i <= n){
            cout << i << endl;
            n -= i;
        }
        if(n <= 0) break;
    }
    return 0;
}


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

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
lb = len(b)
j = len(b)-1
for i in range(len(a)):
    if(a[i] > K):
        break
    while(a[i]+b[j] > K):
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

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; }


// nums[i] := i 番目の連結成分の {左ノード数, 右ノード数}, 「dir = 1: 左、-1: 右」
using pint = pair<int,int>;
using Graph = vector<vector<int> >;

bool dfs(const Graph &G, int v, int vdir, pint &num, vector<int> &dir) {
    bool res = true;
    dir[v] = vdir;
    if (vdir == 1) ++num.first;
    else if (vdir == -1) ++num.second;
    for (auto nv : G[v]) {
        if (dir[nv] == 0) {
            if (!dfs(G, nv, -vdir, num, dir)) res = false;
        }
        else if (dir[nv] != -vdir) res = false;
    }
    return res;
}

bool isbipartite(const Graph &G, vector<pint> &nums) {
    bool res = true;
    int N = (int)G.size();
    vector<int> dir(N, 0);
    for (int v = 0; v < N; ++v) {
        if (dir[v] != 0) continue;
        pint num = {0, 0};
        if (!dfs(G, v, 1, num, dir)) res = false;
        nums.push_back(num);
    }
    return res;
}

const int INF = 1<<29;

int main() {
    int V, E; cin >> V >> E;
    Graph G(V);
    for (int i = 0; i < E; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    // 二部グラフ判定して、左ノード数と右ノード数の差分ごとに集計
    vector<pint> nums;
    if (!isbipartite(G, nums)) {
        cout << -1 << endl;
        return 0;
    }
    map<int,int> ma;
    for (auto p : nums) ma[abs(p.first - p.second)]++;
    
    // DP
    int geta = 0;
    vector<int> dp(V*2+10, INF);
    dp[0] = 0;
    for (auto it = ma.begin(); it != ma.end(); ++it) {
        int diff = it->first;
        geta += diff * it->second;
        for (int v = 0; v <= V*2; ++v) {
            if (dp[v] < INF) dp[v] = 0;
        }
        for (int v = 0; v <= V*2; ++v) {
            if (v + diff * 2 <= V*2 && dp[v] < it->second) chmin(dp[v + diff*2], dp[v] + 1);
        }
    }

    // 集計
    int diff = V;
    for (int v = 0; v <= V*2; ++v) {
        if (dp[v] < INF) diff = min(diff, abs(v-geta));
    }
    long long a = (V + diff)/2, b = (V - diff)/2;
    cout << a * b - E << endl;
}


Measured memory_bytes: 9852
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

namespace uf {
    vector<int> par, rank;
    vector<int> memo;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        memo.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            memo[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            memo[y] += memo[x];
        } else {
            par[y] = x;
            memo[x] += memo[y];
            if (rank[x] == rank[y])rank[x]++;
        }
    }

    int size(int x) {
        return memo[root(x)];
    }
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int N, M;
    cin >> N >> M;
    uf::init(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uf::unite(x, y);
    }
    set<int> a;
    for (int i = 0; i < N; i++) {
        a.insert(uf::root(i));
    }
    cout << a.size() << endl;
}

Measured memory_bytes: 6144
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        System.out.println(Math.min(x, y) + " " + (x + y <= n ? 0 : x + y - n));
    }
}


Measured memory_bytes: 24404
#include<stdio.h>
int main(void){
	
	int w,h,x,y,r;
	
	
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	
	
	
	if(x<r || x+r>w || y<r || y+r>h ){
		
		printf("No\n");
		
		}
		
	else{printf("Yes\n");}
	
	return 0;
}

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

int main() {
	int a, b, i;
	double sum;
	while(cin >> a >> b){
		sum = a + b;
		for(i = 1; sum >= 10; i++){
			sum /= 10;
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
#define for_each(it,a) for(__typeof a.begin() it = a.begin();it!=a.end();it++)
template<class T> inline void chmin(T& a, T b) { if( b < a ) a = b; }

int n, m;
struct edge{
  int pos, dang;
  vector < int >  value;
  edge( int pos, int dang): pos(pos), dang(dang), value( (n + 1) / 2 + 1, INF){};
};
int main(){

  while( scanf("%d %d", &n, &m) , n){
    vector< vector < edge > > info(n + 2);

    for(int i = 0; i < n; i++){
      int k;
      scanf("%d", &k);
      for(int j = 0; j < k; j++){
        int t, d;
        scanf("%d %d", &t, &d);
        info[i].push_back( edge( t, d));
      }
    }
    for_each( it, info[0]) it -> value[m] = 0;
    for_each( it, info[1]) it -> value[m - 1] = 0;
    int ret = INF;
    for( int i = 0; i < n; i++){
      for_each( now, info[i]){
        for(int j = m; j >= 0; j--){ //ジャンプできる残り回数
          int& cost = now -> value[j], dang = now -> dang, pos = now -> pos;
          if( cost == INF) continue;
          if(j > 0){ //ジャンプしてみる
            for_each( next, info[i + 2]){
              chmin( next -> value[j - 1], cost + (dang + next -> dang) * abs( pos - next -> pos));
            }
          }
          for_each( next, info[i + 1]){
            chmin( next -> value[j], cost + (dang + next -> dang) * abs( pos - next -> pos));
          }
        }
      }
    }
    for_each(it,info[n - 1]) chmin( ret, *min_element( it->value.begin(), it->value.end()));
    for_each(it,info[n - 2]) chmin( ret, *min_element( it->value.begin() + 1, it->value.end()));
    cout << ret << endl;
  }
}

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

int main(){
  string S;
  cin>>S;
  int N=S.length();

  
  string F,B;
  F=S.substr(0,(N-1)/2);
  B=S.substr((N+3)/2-1,N-1);
  
  int M=(N-1)/2;
  for (int i=0;i<M;i++){
    if(S.at(i)!=S.at(N-1-i)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  
  if(N==3){
    cout<<"Yes"<<endl;
    return 0;
  }
  

  
  
  //cout<<F<<"*"<<B<<N<<"#"<<M<<endl;
  
  for(int i=0;i<(M/2);i++){    
    if(F.at(i)!=F.at(M-i-1)){      
      cout<<"No"<<endl;
      return 0;
    }
  }
  
 // for(int i=0;i<(M/2);i++){
  // if(B.at(M+i)!=B.at(N-1-i)){
  //    cout<<"No"<<endl;
 //     return 0;
 //   }
 // }
  
  cout<<"Yes"<<endl;

  
  return 0;
}




 

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
int temp=n;
String ans="";
if(n==0){
    System.out.println(0);
}else{
while(temp!=0){
if(temp%(-2)==0){
ans="0"+ans;
}else{
ans="1"+ans;
}
if(temp%(-2)==-1){temp=temp/(-2)+1;}else{temp/=(-2);}
}
System.out.println(ans);
}
}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
#define LL long long
LL ans;
int n;
vector <int> bi[N];
char s[N];
int mxl[N], m2l[N];
int mns[N], vs[N];
void dfs1(int t, int f)
{
    if (s[t] == '1') vs[t] = 1; mns[t] = 1e9;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            dfs1(bi[t][i], t);
            if (mxl[bi[t][i]] + 1 >= mxl[t]) m2l[t] = mxl[t], mxl[t] = mxl[bi[t][i]] + 1;
            else if (mxl[bi[t][i]] + 1 >= m2l[t]) m2l[t] = mxl[bi[t][i]] + 1;
            if (vs[bi[t][i]] && mxl[bi[t][i]] + 1 <= mns[t]) mns[t] = mxl[bi[t][i]] + 1;
            vs[t] += vs[bi[t][i]];
        }
}
void dfs2(int t, int f, int w, int u)
{
    int nmx = mxl[t], nm2 = m2l[t];
    if (w >= nmx) nm2 = nmx, nmx = w;
    else if (w >= nm2) nm2 = w;
    int vvv = mns[t]; if (s[t] == '1') vvv = 0;
    if (u) vvv = min(vvv, w);
    int res = max(0, nmx + 1 - max(1, nmx - nm2 - 1) - vvv);
    ans += res;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
            dfs2(bi[t][i], t, max(w, mxl[t] == mxl[bi[t][i]] + 1? m2l[t]: mxl[t]) + 1, u + vs[t] - vs[bi[t][i]]);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; ++ i)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        bi[a].push_back(b);
        bi[b].push_back(a);
    }
    scanf("%s", s + 1);
    ans = 1;
    dfs1(1, 1);
    dfs2(1, 1, 0, 0);
    printf("%lld\n", ans);
}


Measured memory_bytes: 32256
#include <stdio.h>

int main(){
    int A,B,X;
    scanf("%d %d %d",&A,&B,&X);
          
          
          
    if( A <= X && X <= A+B ){
      printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}
      
      
      

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

int main(){
  int n,sum=0; cin>>n;
  vector<int> w(n);
  for(int i=0;i<n;i++){
    cin>>w[i];
    sum+=w[i];
  }
  int ans=INT_MAX;
  for(int t=0;t<n-1;t++){
    int s1=0;
    for(int i=0;i<=t;i++){
      s1+=w[i];
    }
    ans=min(ans,abs(sum-s1*2));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>

const int mod = 1000000007;
//const int mod = 998244353;
int maximum(int a, int b) { return a < b ? b : a; }
bool same(char*s, char*t) {
	for (int i = 0;; i++) {
		if (s[i] != t[i])return false;
		if (s[i] == 0) {
			return true;
		}
	}
}

int main() {
	char S[101];
	char T[100]{};
	scanf("%s %s", S, T);
	int A, B;
	scanf("%d %d", &A, &B);
	char U[100];
	scanf("%s", U);
	if (same(T, U)) {
		B--;
	}
	else {
		A--;
	}
	printf("%d %d", A, B);
	return 0;
}

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

using namespace std;
using u64 = std::uint_fast64_t;

const int MOD = 1000000007;

int powermod(int x, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = 1LL * res * x % mod;
    x = 1LL * x * x % mod;
    n /= 2;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<u64> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  map<u64, int> cnts;
  for (int i = 0; i < N; i++) {
    u64 a = A[i];
    for (int p = 2; p * p < a + 1; p++) {
      int c = 0;
      while (a % p == 0) {
        a /= p;
        c++;
      }
      if (c > 0) cnts[p] = max(cnts[p], c);
    }
    if (a > 0) cnts[a] = max(cnts[a], 1);
  }

  u64 l = 1;
  for (auto it = cnts.begin(); it != cnts.end(); it++) {
    l = l * powermod(it->first, it->second, MOD) % MOD;
  }

  u64 res = 0;
  for (int i = 0; i < N; i++) {
    res = (res + l * powermod(A[i], MOD - 2, MOD)) % MOD;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6+10;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, ans = 0; 
	cin >> n;
	vector<int> a(n), cnt(MX);
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		cnt[a[i]]++;
	}
	vector<bool> good(MX + 1, 1);
	for (int i = 1; i <= MX; ++i){
		if (cnt[i]){
			for (int j = i + i; j <= MX; j += i){
				good[j] = 0;
			}
		}
	}
	for (auto x: a){
		if (good[x] && cnt[x] == 1) ans++;
	}
	cout << ans << '\n';

}




Measured memory_bytes: 8208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int N,Y;
	cin>>N>>Y;
	for(int i=0;i<=N;i++){
		for(int j=0;(i+j)<=N;j++){
			int k=N-(i+j);
			if(Y==1000*i+5000*j+10000*k){
				cout<<k<<" "<<j<<" "<<i<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, k, a[212345];

    cin >> n >> k;
    REP(i, n)
    {
        cin >> a[i];
        a[i] = a[i] % k - 1;
        a[i] = (a[i] + k) % k;
    }

    if (k == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    int b[212345];
    b[0] = 0;
    REP(i, n)
    {
        b[i + 1] = (b[i] + a[i]) % k;
    }

    map<int, int> mp;

    mp[0] = 1;

    ll res = 0;

    for (int i = 1; i <= n; i++)
    {
        res += mp[b[i]];

        mp[b[i]] += 1;

        if (i - (k - 1) >= 0)
            mp[b[i - (k - 1)]]--;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 11264
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<iostream>
using namespace std;
const int maxm=2e5+7;
typedef long long ll;
int n,l,r,ans;
int a[2*maxm];
bool check(int k)
{
  for(int i=0;i<n-1;i++)
  {
     if((a[n+i]>=k&&a[n+i+1]>=k)||(a[n-i]>=k&&a[n-i-1]>=k)) return 1;
     if((a[n+i]<k&&a[n+i+1]<k)||(a[n-i]<k&&a[n-i-1]<k)) return 0;
  }
  return a[1]>=k;
}
int main()
{
 scanf("%d",&n);
 for(int i=1;i<=2*n-1;i++)
 {
    scanf("%d",&a[i]);	
 }
 l=1,r=2*n-1;
 while(l<=r)
 {
    int mid=(l+r)>>1;
	if(check(mid))
	{
	   ans=mid;
	   l=mid+1;	
	}
	else r=mid-1;
 }
 printf("%d\n",ans);
 return 0;	
}

Measured memory_bytes: 1024
s = input()
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll h,a;
    cin >> h >> a;
    if (h<a){
        cout << 1 << endl;
        return 0;
    }
    if (h%a==0){
        cout << h/a << endl;
    }else{
        cout << h/a + 1 << endl;
    }
}

Measured memory_bytes: 256
import sys
from collections import deque

n,q = map(int,input().split())
f = lambda n,t: (n,int(t))
queue = deque(f(*l.split()) for l in sys.stdin)

t = 0
while queue:
	name,time = queue.popleft()
	t += min(q, time)
	if time > q:
		queue.append((name, time-q))
	else:
		print(name,t)


Measured memory_bytes: 12556
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var h = long.Parse(input[0]);
        var w = long.Parse(input[1]);

        if (h == 1 || w == 1)
        {
            Console.WriteLine(1);
        }
        else
        {
            if ((h * w) % 2 == 0)
            {
                Console.WriteLine((h * w / 2));
            }
            else
            {
                Console.WriteLine((h * w / 2) + 1);

            }
        }
    }
}


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

using namespace std;

int main(void){
  int x,y,a,b,n[30];
  char s;

  cin >> y >> x;
  for(int i=0;i<y;i++)n[i]=i+1;

  for(int i=0;i<x;i++){
    cin >> a >> s >> b;
    swap(n[a-1],n[b-1]);
  }
  for(int i=0;i<y;i++)cout << n[i] << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int n,a[2005],in[2005];
bool vis[2005];
vector<int> g1[2005],g2[2005];
void dfs(int x)
{
	vis[x]=1;
	for(int i=0;i<g1[x].size();i++)
		if(!vis[g1[x][i]])
		{
			in[g1[x][i]]++;
			g2[x].push_back(g1[x][i]);
			dfs(g1[x][i]);
		}
}
void topo()
{
	priority_queue<int> pq;
	for(int i=1;i<=n;i++)
		if(!in[i])
			pq.push(i);
	while(!pq.empty())
	{
		int now=pq.top();
		pq.pop();
		cout<<a[now]<<' ';
		for(int i=0;i<g2[now].size();i++)
		{
			in[g2[now][i]]--;
			pq.push(g2[now][i]);
		}
	}
	cout<<endl;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(__gcd(a[i],a[j])!=1)
			{
				g1[i].push_back(j);
				g1[j].push_back(i);
			}
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	topo();
	return 0;
}


Measured memory_bytes: 17792