akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;
#include<stdio.h>


int main(void) {
	string s,t;
	int w;
	cin >> s;
	cin >> w;
	for (int i = 0;i < s.length();i++) {
		if (i%w == 0)t = t + s[i];
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	
	string S;
	int K;
	
	cin>>K>>S;
	
	if(S.size() <= K) {
		cout<<S<<endl;
	} else {
		for(int i = 0; i < K; i++){
			cout<<S[i];
		}
		cout<<"..."<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3104
from fractions import gcd

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    M = [0] * N
    L = [0] * (N+2)
    R = [0] * (N+2)
    for i in range(1,N+1):
        i_r = N-i
        L[i] = gcd(L[i-1], A[i-1])
        R[i_r] = gcd(R[i_r+1], A[i_r])
        
    for i in range(N):
        M[i] = gcd(L[i], R[i+1])

    print(max(M))
    
solve()

Measured memory_bytes: 16116
#include <iostream>

using namespace std;


int main()
{
    int r, d ,x ,xx;
    cin >> r >> d >> x;
    for(int i=0 ; i<10 ; i++)
    {
          xx = r*x - d;
          x = xx;
          cout << xx << endl;
    }
    return 0;
}


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

#define ll long long
#define inf 0x3f3f3f3f 
#define il inline 

#define in1(a) a=read()
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
#define out(a) printf( "%d" , a ) 
#define outn(a) out(a),putchar('\n')

#define I_int int 
inline I_int read() {
	
    I_int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) {
        if( c == '-' ) f = -1 ;
        c = getchar() ;
    }
    while( c >= '0' && c <= '9' ) {
        x = (x << 1) + (x << 3) + c - 48 ;
        c = getchar() ;
    }
    return x * f ;
}
#undef I_int

using namespace std ;

#define N 100010

int n ;
int b[ N ] ;
int a[ N ] ;
ll ans = 0 ;

int main() {
	in1( n ) ;
	for( int i = 1 ; i <= n ; i ++ ) in1( a[ i ] ) ;
	sort( a+1 , a+n+1 ) ;
	int l = 1 , r = n , mid = ( l + r ) >> 1 ; 
	if( n % 2 ) {
		b[ mid ] = a[ r -- ] ;
		for( int i = mid - 1 ; i ; i -- ) {
			if( ( mid - i ) % 2 ) b[ i ] = a[ l ++ ] , b[ mid + mid - i ] = a[ l ++ ] ;
			else b[ i ] = a[ r -- ] , b[ mid + mid - i ] = a[ r -- ] ;
		}
		ll sum = 0 ;
		for( int i = 2 ; i <= n ; i ++ ) sum += abs( b[ i ] - b[ i - 1 ] ) ;
		ll t = sum ;
		l = 1  , r = n ;
		b[ mid ] = a[ l ++ ] ;
		for( int i = mid - 1 ; i ; i -- ) {
			if( ( mid - i ) % 2 == 0 ) b[ i ] = a[ l ++ ] , b[ mid + mid - i ] = a[ l ++ ] ;
			else b[ i ] = a[ r -- ] , b[ mid + mid - i ] = a[ r -- ] ;
		}
		sum = 0 ;
		for( int i = 2 ; i <= n ; i ++ ) sum += abs( b[ i ] - b[ i - 1 ] ) ;
		printf( "%lld\n" , max( t , sum ) ) ;
		return 0 ;
	}
	b[ mid ] = a[ r -- ] ;
	b[ mid + 1 ] = a[ l ++ ] ;
	for( int i = mid - 1 ; i ; i -- ) {
		if( ( mid - i ) % 2 ) b[ i ] = a[ l ++ ] , b[ n - i + 1 ] = a[ r -- ] ;
		else b[ i ] = a[ r -- ] , b[ n - i + 1 ] = a[ l ++ ] ;
	}
	ll sum = 0 , t = 0 ;
	for( int i = 2 ; i <= n ; i ++ ) {
		sum += abs( b[ i ] - b[ i - 1 ] ) ;
	}
	t = sum ;
	l = 1 , r = n ;
	b[ mid + 1 ] = a[ r -- ] ;
	b[ mid ] = a[ l ++ ] ;
	for( int i = mid - 1 ; i ; i -- ) {
		if( ( mid - i ) % 2 == 0 ) b[ i ] = a[ l ++ ] , b[ n - i + 1 ] = a[ r -- ] ;
		else b[ i ] = a[ r -- ] , b[ n - i + 1 ] = a[ l ++ ] ;
	}
	sum = 0 ;
	for( int i = 2 ; i <= n ; i ++ ) {
		sum += abs( b[ i ] - b[ i - 1 ] ) ;
	}
	printf( "%lld\n" , max( sum , t ) ) ; 
}

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

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

using namespace std;

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

    int array[26];
    REPI(i, 26) array[i] = 0;
    char c;
    while(cin >> c) array[int(c) - int('a')]++;

    REPI(i, 26){
        if(array[i] % 2){
            cout << "No";
            return 0;
        }
    }cout << "Yes";
}


Measured memory_bytes: 256
#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 <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  ll N, K;
  cin >> N >> K;
  
  ll ans = 0;
  
  ll div = N/K;
  ans += div * div * div;

  if(K%2 == 0){
    ll div2 = N / (K/2);
    ans += (div2 - div) * (div2 - div) * (div2 - div);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#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
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, s = 0;
  scanf("%d", &n);
  vector<pii> a(n), b(n); v1b c(n, 1);
  rep(i, n) scanf("%d %d", &a[i].fi, &a[i].se);
  rep(i, n) scanf("%d %d", &b[i].fi, &b[i].se);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  rep(i, n){
    int m = -1, t = 0;
    while(a[t].fi < b[i].fi && t < n){
      if(c[t] && a[t].se < b[i].se) m = max(m, a[t].se);
      ++t;
    }
    rrep(j, t){
      if(c[j] && m == a[j].se){
        ++s;
        c[j] = 0;
        break;
      }
    }
  }
  printf("%d\n", s);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;
long long euclid(long long x,long long y){
    long long a=max(x,y);
    long long b=min(x,y);
    if(a%b==0)return b;
    else{
        return euclid(b,a%b);
    }
}

int main(){
    int K;
    cin>>K;
    bool jud=false;
    if(K<10)cout<<K<<endl;
    else{
        ll cnt=9;
        vector<string> naka={"1","2","3","4","5","6","7","8","9"};
        for(ll t=0;t<naka.size();t++){
            string x=naka.at(t);
            char c=x.at(x.length()-1);
            int k=c-'0';
            if(k==0){
                for(int j=0;j<=1;j++){
                    naka.push_back(x+to_string(j));
                    cnt++;
                    if(cnt==K){
                        jud=true;
                        break;
                    }
                }
            }
            else if(k==9){
                for(int j=8;j<=9;j++){
                    naka.push_back(x+to_string(j));
                    cnt++;
                    if(cnt==K){
                        jud=true;
                        break;
                    }
                }
            }
            else{
                for(int j=k-1;j<=k+1;j++){
                    naka.push_back(x+to_string(j));
                    cnt++;
                    if(cnt==K){
                        jud=true;
                        break;
                    }
                }
            }
            if(jud)break;
        }
        cout<<naka.at(cnt-1)<<endl;
    }
    
     
}


Measured memory_bytes: 5764
import sys
import numpy as np

n, k = map(int, input().split())

p = np.array([list(map(int, input().split()))]).reshape(-1)

sum_max = p[:k].sum()
mx = sum_max
index_max = -1
for i in range(1, n-k+1):
    mx += p[i+k-1]
    mx -= p[i-1]
    if mx > sum_max:
        sum_max = mx
        index_max = i
print(str((sum_max+k) / 2))

Measured memory_bytes: 33984
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long
#define PI 2 * acos(0.0)
#define MAX 1000000000
#define INF 1000000 
#define M 1000000007
using namespace std;
int main(){
   fast_io
   ll n;
   cin>>n;
   ll sieve[100006];
   set_zero(sieve);
   sieve[1] = 1;
   ll y = 100005;
   for(ll i = 2;i<=y;i++){
      if(sieve[i] == 0){
         if(i >= n){
            cout<<i<<endl;
            break;
         }
         for(ll j = i*2;j<=y; j += i){
            sieve[j] = 1;
         }
      }
   }
   return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll ab, bc, ca;
  cin >> ab >> bc >> ca;

  cout << ab * bc / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    cout << (1900 * m + 100 * (n - m))*pow(2, m) << endl;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
W = list(map(lambda x: int(x), input().split()))
#print(N)
#print(W)
ans = float('inf')
for i in range(1, N):
  S1 = sum(W[:i])
  S2 = sum(W[i:])
  ans = min(ans, abs(S1-S2))
print(ans)


Measured memory_bytes: 38384
program main
  implicit none
  real(8) W,H,x,y,ans1
  integer ans2 
  read(*, *)W,H,x,y
  ans1 = W*H*0.5
  if(2*x == W .and. 2*y == H) then
    ans2 = 1
  else
    ans2 = 0
  end if
  write(* ,*)ans1,ans2
end program main


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

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> a(N), b(N);
  intmax_t sum_a=0, sum_b=0;
  for (size_t i=0; i<N; ++i) {
    scanf("%d", &a[i]);
    sum_a += a[i];
  }
  for (size_t i=0; i<N; ++i) {
    scanf("%d", &b[i]);
    sum_b += b[i];
  }

  if (a == b)
    return !printf("Yes\n");

  intmax_t count=sum_b-sum_a;
  for (size_t i=0; i<N; ++i) 
    if (a[i] < b[i])
      count -= (b[i]-a[i]+1)/2;

  printf("%s\n", count<0? "No":"Yes");
}


Measured memory_bytes: 256
r, g, b, n = gets.chomp.split(' ').map(&:to_i)

count = 0


3001.times do |i|
  3001.times do |j|
    k = n - r*i - j*g
    count += 1 if k >= 0 && (k % b).zero?
#     break if r * i + g * j > n
  end
#   break if r * i > n
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;

int n;
int a[maxn];

int main()
{
    IO;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans = 0;
    int last = 0;
    for(int i=0;i<n;i++)
    {
        ans += abs(last-a[i]);
        last = a[i];
    }
    ans += abs(last);
    last = 0;
    for(int i=0;i<n;i++)
    {
        if((a[i]<=last&&a[i]>=a[i+1])||(a[i]<=a[i+1]&&a[i]>=last))
            cout<<ans<<endl;
        else
        {
            int low = min(last,a[i+1]);
            int high = max(last,a[i+1]);
            if(a[i]>high)
                cout<<ans-abs(high-a[i])*2<<endl;
            else
                cout<<ans-abs(a[i]-low)*2<<endl;
        }
        last = a[i];
    }
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

//再帰関数による
void dfs_visit(int u)
{
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for ( v = 0; v < n; v++ )
	{		
		if ( M[u][v] == 0 ) continue;
		if ( color[v] == WHITE )
		{
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs()
{
	int u;
	// 初期化
	for ( u = 0; u < n; u++ ) color[u] = WHITE;
	tt = 0;

	for ( u = 0; u < n; u++ )
	{
		if ( color[u] == WHITE ) dfs_visit(u);
	}

	for ( u = 0; u < n; u++ )
	{
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}


int main()
{
	int u, v, k, i, j;

	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 %d", &u, &k);
		u--;
		for ( j = 0; j < k; j++ )
		{
		scanf("%d", &v);
		v--;
		M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}


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

int main() {
    int n,k;cin>>n>>k;
    int a[n];rep(i,n)cin>>a[i];
    
    for(int i = k;i<n;++i){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
	return 0;
}

Measured memory_bytes: 4396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N - 1];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < N - 1; i++) {
			C[i] = sc.nextInt();
		}
		sc.close();
		int r = 0;
		int c = A[0];
		for(int i = 0; i < N; i++) {
			r += B[A[i] - 1];
			if(c + 1 == A[i]) {
				r += C[c - 1];
			}
			c = A[i];
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n,p;
    cin>>n>>p;
    if(!(n||p))break;
    vector<int> a(n,0);
    int op=p;
    int i=0;
    while(1){
      if(p>0){
        a[i]++;p--;
        if(p==0&&a[i]==op){
          cout<<i<<endl;
          break;
        }
      }else{
        p=a[i];a[i]=0;
      }
      i++;
      if(i==n)i=0;
    }
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
struct threeElements{
int _1st,_2nd,_3rd;
};
vector<vector<int>>adj(100);
ll n;
ll a[2000009];
bool check(string s,string t)
{
    int n1=s.length(),n2=t.length(),j=0;
    for(int i=0;i<n1;i++)
    {
    if(s[i]==t[j])
            j++;
        if(j==n2)
            return 1;
    }
    return 0;
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   //18:52
    string s;
    cin>>s;
    map<char,bool>mp;
    for(int i=0;i<s.length();i++)
    {
        if(mp[s[i]])
            return cout<<"no",0;
        mp[s[i]]=1;
    }
    cout<<"yes";
}


Measured memory_bytes: 3600
function Main(input) {
  inp = input.split("\n")[0];
  var ans = 890016;
  for(var i = 0; i < inp.length - 2; i++) {
    ans = Math.min(ans, Math.abs(753 - parseInt(inp.slice(i, i + 3))));
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    vector<pair<pair<string, int>, int>> v(n);
    for(int i=0; i<n; i++){
        string s; cin>>s;
        int p; cin>>p;
        v[i] = make_pair(make_pair(s, -p), i);
    }

    sort(v.begin(), v.end());

    for(int i=0; i<n; i++){
        cout << v[i].second + 1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define N 200010
#define ll long long
using namespace std;

int n,t,tag,cnt1,cnt2,st[N],control[N],du[N],sz[N];
ll fac[N],inv[N];
vector<int>e[N],tp[N],cir,lt;
bool vis[N],onc[N];

ll fpow(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ret;
}

void dfs(int u,int fa){
	st[++t]=u;vis[u]=1;cnt1++;lt.push_back(u);
	for(int i=0;i<e[u].size();i++)
	  if(e[u][i]!=fa&&!onc[e[u][i]]){
	  	int v=e[u][i];cnt2++;
	  	if(!tag&&vis[v]){
	  		tag=1;
	  		while(st[t]!=v)cir.push_back(st[t]),onc[st[t]]=1,t--;
	  		cir.push_back(st[t]);onc[st[t]]=1;t--;
		}
		else if(!vis[v])dfs(v,u);
	  }
	if(!tag)t--;
}

void dfs1(int u,int fa){
	for(int i=0;i<e[u].size();i++){
		if(e[u][i]==control[u])break;
		tp[u].push_back(e[u][i]);du[e[u][i]]++;
	}
	for(int i=0;i<e[u].size();i++)
	  if(e[u][i]!=fa&&!onc[e[u][i]])
	  	control[e[u][i]]=u,dfs1(e[u][i],u);
}

ll dfs2(int u,int fa){
	ll ret=sz[u]=1;
	for(int i=0;i<tp[u].size();i++)
	  if(tp[u][i]!=fa){
	  	ret=ret*dfs2(tp[u][i],u)%mod;
	  	sz[u]+=sz[tp[u][i]];
	  }
	return ret*inv[sz[u]]%mod;
}

ll solve1(){
	ll ret=1;
	for(int i=0;i<lt.size();i++)
	  if(!du[lt[i]])
	    ret=ret*dfs2(lt[i],0)%mod;
	for(int i=0;i<lt.size();i++)tp[lt[i]].clear(),du[lt[i]]=0;
	return ret;
}

ll solve(int u){
	ll ret=0;
	t=tag=cnt1=cnt2=0;
	cir.clear();lt.clear();
	dfs(u,0);
	if(cnt1!=cnt2)return 0;
	
	for(int i=0;i<cir.size()-1;i++)control[cir[i]]=cir[i+1];
	control[cir[cir.size()-1]]=cir[0];
	for(int i=0;i<cir.size();i++)dfs1(cir[i],0);
	ret+=solve1();
	
	for(int i=1;i<cir.size();i++)control[cir[i]]=cir[i-1];
	control[cir[0]]=cir[cir.size()-1];
	for(int i=0;i<cir.size();i++)dfs1(cir[i],0);
	ret+=solve1();
	
	return ret;
}

int main()
{
	scanf("%d",&n);
	for(int i=1,x,y;i<=n*2;i++)scanf("%d%d",&x,&y),e[x].push_back(y+n),e[y+n].push_back(x);
	for(int i=1;i<=n*2;i++)sort(e[i].begin(),e[i].end());
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n*2;i++)fac[i]=fac[i-1]*i%mod;
	for(int i=2;i<=n*2;i++)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
	ll ans=fac[n*2];
	for(int i=1;i<=n*2;i++)
	  if(!vis[i])
	    ans=ans*solve(i)%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 30068
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    long mod = 1000000007;
    void solve() throws IOException {
        int n = in.nextInt();
        long[] a = new long[n];
        long[] s = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            s[i] = a[i];
            if (i > 0) s[i] += s[i - 1];
        }
        MultiSet<Long> ms = new MultiSet<>();
        ms.add(0L);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += ms.get(s[i]);
            ms.add(s[i]);
        }
        System.out.println(ans);
    }
}

@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Integer>{
    @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;}
    public void add(T key,int v){put(key,get(key)+v);}
    public void add(T key){put(key,get(key)+1);}
    public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
    public MultiSet<T> merge(MultiSet<T> set)
    {MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
        for(Entry<T,Integer>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}

Measured memory_bytes: 56472
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(NULL);
int a,b;
cin>>a>>b;
float x1,x2,y1,y2;
x1=a*12.5;
x2=x1+12.499;
y1=10*b;
y2=y1+9.999;
if(x2<y1||y2<x1)
cout<<"-1";
else
{
	float mn,mx;
	mn=max(x1,y1);
	mx=min(x2,y2);
int x=mn;
if(float(x)==mn)
cout<<x;
else 
{
x++;
if(float(x)>mx)
cout<<-1;
else
cout<<x;	
}
}
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(X, A, B) :- X is (A + B) mod 24.

main :-
    get_number(A, B),
    f(X, A, B),
    writeln(X).


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

int main(){
    vector<int> a;
    int b;
    for(int i = 0; i < 5; i++){
        cin >> b;
        a.push_back(b);
    }
    for(int i = 0; i < 5; i++){
        if(a[i] == 0){
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N,M,X;
  cin >> N >> M >> X;
  vint C(N);
  vector<vector<int>> A(N,vector<int>(M));
  REP(i,N){
    cin >> C[i];
    REP(j,M){
      cin >> A[i][j];
    }
  }
  
  bool ans_flag = false;
  ll ans = 1e10;
  for(int i=0; i<(1<<N); i++){
    ll yen = 0;
    vint total(M);
    REP(j,N){
      if(i & (1<<j)){
        yen += C[j];
        REP(k,M){
          total[k] += A[j][k];
        }
      }
    }
    bool flag = true;
    REP(j,M){
      if(X > total[j])flag = false;
    }
    if(flag){
      ans_flag = true;
      ans = min(ans,yen);
    }
  }
  if(ans_flag){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double dp[50][50];
double c[50];
double PI=acos(-1.0);
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%lf",c+i);
		for(int i=0;i<a;i++)c[i]*=PI*2;
		double ret=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++)for(int k=0;k<=b;k++)dp[j][k]=-999999999;
			dp[0][1]=0;
			for(int j=0;j<a;j++){
				for(int k=1;k<b;k++){
					for(int l=j+1;l<a;l++){
						double d=c[(l+i)%a]-c[(j+i)%a];
						dp[l][k+1]=max(dp[l][k+1],dp[j][k]+sin(d)/2);
					}
				}
			}
			for(int j=0;j<a;j++){
				double d=c[i]-c[(j+i)%a];
				ret=max(ret,dp[j][b]+sin(d)/2);
			}
		}
		printf("%.6f\n",ret);
	}
}

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

int H, W, N=0;
char M[10][10];

int main() {
  memset(M, 0, sizeof(M));
  scanf("%d%d", &H, &W);
  for(int i = 0; i < H; ++i)
    scanf("%s", M[i]);

  for(int i = 0; i < H; ++i)
    for(int j = 0; j < W; ++j)
      if(M[i][j] == '#') ++N;

  printf("%s\n", N==W+H-1 ? "Possible" : "Impossible");
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        static int MOD = (int)1e9 + 7;
        
        String S;
        long mul = 1L;
        long patA = 0, patB = 0, patC = 0;
        
        void solve(InputReader in, PrintWriter out) {
            S = in.next();
            
            for (int i = 0; i < S.length(); ++i) {
                char c = S.charAt(i);
                if (c == 'A') {
                    patA = (patA + mul) % MOD;
                } else if (c == 'B') {
                    patB = (patB + patA) % MOD;
                } else if (c == 'C') {
                    patC = (patC + patB) % MOD;
                } else {
                    patC = (3*patC + patB) % MOD;
                    patB = (3*patB + patA) % MOD;
                    patA = (3*patA + mul) % MOD;
                    mul = (mul*3) % MOD;
                }
            }

            out.println(patC);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        long nextLong() { return Long.parseLong(next()); }

        long[] nextLongArray(int n) {
        	long[] arr = new long[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextLong();
        	}
        	return arr;
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    string s;
    map<string,int> mp;
    rep(i,n) {
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    long long cnt=0;
    for(auto iter=mp.begin(); iter!=mp.end();iter++){
        long long a=iter->second;
        cnt +=a*(a-1)/2;
    }
    cout<< cnt;
}

Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int main(void){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int cnt = 0;
    for(int i = 0;i * r <= n;i++){
        for(int j = 0;j * b <= n - r * i;j++){
            if((n - r * i - b * j) % g == 0){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, Q, *A = map(int, read().split())
point = np.zeros(N+1)

for i in A:
    point[i] += 1
point += K - Q
print(*['Yes' if i > 0 else 'No' for i in point[1:]], sep='\n')


Measured memory_bytes: 21464
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;

struct A
{
    long long ct;
    long long num;
    long long id;
    long long sc;
} a[100005];

bool cmp(A a,A b)
{
    if(a.ct==b.ct)
        return a.num<b.num;
    return a.ct<b.ct;
}

bool cmp2(A a,A b)
{
    return a.sc<b.sc;
}

long long c[100010];

int main()
{
    long long n,m;
    long long i,j;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        memset(c,0,sizeof(c));
        for(i=0; i<m; i++)
        {
            scanf("%lld%lld",&a[i].ct,&a[i].num);
            a[i].sc=i+1;
        }
        sort(a,a+m,cmp);
        for(j=0; j<m; j++)
        {
            a[j].id=1+c[a[j].ct];
            c[a[j].ct]++;
        }
        sort(a,a+m,cmp2);
        for(i=0; i<m; i++)
            printf("%06lld%06lld\n",a[i].ct,a[i].id);
    }
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define fi first
#define se second 
using namespace std;
const int N=100010;
int n;map<int,int>s;
map<int,int>::iterator it;
typedef pair<int,int>pii;
int main(){
	scanf("%d",&n);	
	for(int i=1,x;i<=n;++i){scanf("%d",&x);s[x]++;}
	if(s.size()==1&&(*s.begin()).fi==0)return puts("Yes"),0;
	if(n%3)puts("No");
	else{
		if(s.size()>3||s.size()==1)return puts("No"),0;
		else if(s.size()==2){
			it=s.begin();
			pii x=*it++;
			pii y=*it++;
			if(x.fi==0&&x.se==n/3)puts("Yes");
			else puts("No");
		}else {
			it=s.begin();
			pii x=*it++;
			pii y=*it++;
			pii z=*it++;
			if((x.fi^y.fi^z.fi)==0&&x.se==y.se&&y.se==z.se)puts("Yes");
			else puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec x(n),y(n);
  for(ll i=0;i<n;i++) cin >> x[i] >> y[i];
  for(ll i=0;i<n;i++) {
    vector<double> d;
    for(ll j=0;j<n;j++) {
      if(i==j) continue;
      d.push_back(atan2(y[j]-y[i],x[j]-x[i]));
    }
    sort(d.begin(),d.end());
    double r=0;
    ll k=d.size();
    for(ll j=0;j<k;j++) {
      d.push_back(d[j]+2*acos(-1));
    }
    for(ll j=0;j<k;j++) {
      r=max(r,acos(-1)-d[j+k]+d[j+1]);
    }
    cout << fixed << setprecision(10) << r/(2*M_PI) << endl;
  }
}

Measured memory_bytes: 4216
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<char> vchar;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<string>> vvstring;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N;
	cin >> N;

	vll A(N), num(N+100);
	for (ll i = 0; i < N; i++)
	{
		cin >> A[i];
		
	}

	
	for (ll i = 0; i < N + 100; i++)
	{
		num[i] = 0;
	}



	for (ll i = 0; i < N; i++)
	{
		num[A[i]]++;
	}


	vll com(N + 100), com2(N + 100);
	for (ll i = 0; i < N + 100; i++)
	{
		com[i] = (num[i]*(num[i]-1))/2;
		com2[i] = ((num[i]-1) * (num[i] - 2)) / 2;

	}

	ll sum = 0;
	for (ll i = 0; i < N + 100; i++)
	{
		sum += com[i];
	}

	for (ll i = 0; i < N; i++)
	{
		cout << sum - (com[A[i]] - com2[A[i]]) << endl;
	}


}



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

int main(){
  int n;
  cin >> n;
  
  if(n < 105){
  	cout << 0 << endl;
  }
  else if(n < 135){
  	cout << 1 << endl;
  }
  else if(n < 165){
  	cout << 2 << endl;
  }
  else if(n < 189){
  	cout << 3 << endl;
  }
  else if(n < 195){
  	cout << 4 << endl;
  }
  else{
  	cout << 5 << endl;
  }
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy

moves = ''

# s -> t (1)
moves += 'U' * dy
moves += 'R' * dx
# t -> s (1)
moves += 'D' * dy
moves += 'L' * dx

# s -> t (2)
moves += 'L'
moves += 'U' * (dy + 1)
moves += 'R' * (dx + 1)
moves += 'D'

# t -> s (2)
moves += 'R'
moves += 'D' * (dy + 1)
moves += 'L' * (dx + 1)
moves += 'U'

print(moves)

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

int main() {
        int N;
        int cnt[105] = {};
        int maxv = 0;
        bool flag = true;

        cin >> N;
        for (int i = 0; i < N; i++) {
                int a;
                cin >> a;
                cnt[a]++;
                maxv = max(maxv, a);
        }
        
        int m = (maxv + 1) / 2;
        if (cnt[m] != 1 + (maxv & 1)) flag = false;

        cnt[m] = 0;
        for (int i = m + 1; i <= maxv; i++) {
                if (cnt[i] < 2) flag = false;
                cnt[i] = 0;
        }
        
        if (!flag || accumulate(cnt, cnt + 105, 0) > 0) {
                cout << "Impossible" << endl;
        } else {
                cout << "Possible" << endl;
        }

        return (0);
}


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

int minx=~0U>>2,sum=0;

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		sum+=x;
		if(x%10)minx=min(minx,x);
	}
	printf("%d\n",sum%10?sum:max(0,sum-minx));
	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    x = list(map(int, input().split()))
    xs = list(sorted(x))
    right = xs[n//2]
    left = xs[n//2-1]
    for xi in x:
        if xi <= left:
            print(right)
        else:
            print(left)

if __name__ == "__main__":
    main()

Measured memory_bytes: 95188
<?php
$f = fopen( 'php://stdin', 'r' );
$line = str_replace(array("\n", "\r"), '', fgets($f));
$stringParts = str_split($line);
$out = 0;
for ($i = 0; $i < 3; $i++) {
    $out = $out + (int)$stringParts[$i];
}
echo($out);

Measured memory_bytes: 4604
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

typedef vector<vector <int>> Graph;




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

    ll w0;

    vector <vector <ll> > v(4); 
    

    //選んだものの重さは、w[0]≦w[i]≦w[0]+3となる
    //4種類の重さのものをそれぞれ何個使うかで全探索
    REP(i, N)
    {
        int w,_v;
        cin >> w >> _v;

        if(i == 0)
        {
            w0 = w;
            v[0].push_back(_v);
        }
        else
        {
            v[w-w0].push_back(_v);
        }
    }

    for(int i = 0; i < 4; ++i)
    {
        sort(v[i].rbegin(), v[i].rend());
    }

    ll res = 0;

    //4種類をそれぞれ何回使うかを全探索
    for(int i = 0; i <= v[0].size(); ++i)
    {
        for(int j = 0; j <= v[1].size(); ++j)
        {
            for(int k = 0; k <= v[2].size(); ++k)
            {
                for(int l = 0; l <= v[3].size(); ++l)
                {
                    ll w=0,vt=0;

                    for(int x = 0; x < i; ++x)
                    {
                        vt += v[0][x];
                    }
                    w += w0 * i;

                    for(int x = 0; x < j; ++x)
                    {
                        vt += v[1][x];
                    }
                    w += (w0+1) * j;
                    for(int x = 0; x < k; ++x)
                    {
                        vt += v[2][x];
                    }
                    w += (w0+2) * k;
                    for(int x = 0; x < l; ++x)
                    {
                        vt += v[3][x];
                    }
                    w += (w0+3) * l;


                    if(w > W)continue;
                    res = max(res, vt);

                }
            }
        }
    }




    cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
W = list(int(x) for x in input().split())

min = 0
for i in range(1,N):
  S1 = W[:i]
  S2 = W[i:]
  if i == 1:
    min = sum(S1) + sum(S2)
  elif min > (abs(sum(S1) - sum(S2))):
    min = abs(sum(S1) - sum(S2))

print(min)

Measured memory_bytes: 3064
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int r;cin >> r;

  cout << r * r;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong


const int maxn = 2e5 + 30;
int n;
int to[maxn];
int ans = 0, k;
vector<int> G[maxn];
int deep[maxn];
void dfs(int x, int fa) {
	for (int i = 0; i < G[x].size(); i++) {
		int v = G[x][i];
		deep[v] = deep[x] + 1;
		dfs(v, x);
	}
}
int du[maxn];
int dis[maxn];
int main() {
	n = ri(); k = ri();
	for (int i = 1; i <= n; i++) {
		to[i] = ri();
	}
	if (k == 1) {
		for (int i = 1; i <= n; i++) {
			if (to[i] != 1) ans++;
		}
		cout << ans << endl; return 0;
	}
	if (to[1] != 1) {
		to[1] = 1;
		ans++;
	}
	for (int i = 2; i <= n; i++) {
		G[to[i]].push_back(i);
		du[to[i]]++;
	}
	dfs(1, 0);
	queue<int> q;
	for (int i = 1; i <= n; i++) {
		if (du[i] == 0) q.push(i), dis[i] = deep[i];
	}
	for (int i = 1; i <= n; i++) dis[i] = deep[i];
	while (!q.empty()) {
		int u = q.front(); q.pop();
		//cout << u << " " << dis[u]  << endl;
		if (dis[u] - deep[u] == k - 1 && to[u] != 1) {
			//cout << "asdasd" << u << " " << deep[u] << " " << dis[u] << endl;
			deep[u] = 1; ans++;
		}
		else dis[to[u]] = max(dis[to[u]], dis[u]);
		du[to[u]]--;
		if (du[to[u]] == 0) q.push(to[u]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 17636
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	string s,t; cin>>s>>t;
	ll a=s.length();
	ll b=t.length();
	ll x=abs(a-b);
	ll ans=10000;
	x++;
	while(x--)
	{
		ll cnt=0;
		for(ll i=0;i<b;i++)
		{
			if(s[i]!=t[i])cnt++;
		}
		ans=min(ans,cnt);
		s.erase(s.begin());
	}
	cout<<ans;
}

int main()
{
	solve();
}
/*




*/


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';
ll const mod = 1e9+7;

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

int main() {
    int n,k;
    cin >> n >> k;
    bool f = true;
    vector<pair<ll,bool>> a(n);
    for (int i = 0;i < n;++i) {
        cin >> a[i].first;
        a[i].second = (a[i].first >= 0);
        if (a[i].second) f = false;
        a[i].first = abs(a[i].first);
    }
    sort(a.begin(),a.end());
    ll ans;
    if (f && k%2) {
        ans = -1;
        for (int i = 0;i < k;++i) (ans *= a[i].first) %= mod;
    } else {
        reverse(a.begin(),a.end());
        ans = 1;
        bool s = true;
        for (int i = 0;i < k;++i) {
            (ans *= a[i].first) %= mod;
            if (!a[i].second) s = !s;
        }
        if (!s) {
            ll w = -1,x = -1,y = -1,z = -1;
            for (int i = k;i < n;++i) if (a[i].second) {
                w = a[i].first;
                break;
            }
            for (int i = k-1;i >= 0;--i) if (!a[i].second) {
                x = a[i].first;
                break;
            }
            for (int i = k;i < n;++i) if (!a[i].second) {
                y = a[i].first;
                break;
            }
            for (int i = k-1;i >= 0;--i) if (a[i].second) {
                z = a[i].first;
                break;
            }
            if ((w < 0 || x < 0) && (y < 0 || z < 0)) ans *= -1;
            else if (w < 0 || x < 0) (ans *= y*pow_mod(z,-1)%mod) %= mod;
            else if (y < 0 || z < 0) (ans *= w*pow_mod(x,-1)%mod) %= mod;
            else if (y*x > w*z) (ans *= y*pow_mod(z,-1)%mod) %= mod;
            else (ans *= w*pow_mod(x,-1)%mod) %= mod;
        }
    }
    cout << (ans+mod)%mod << endl;
    // p_ary(a,0,n);
}

Measured memory_bytes: 6352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<b)
    {
        for(int i=1;i<=b;i++)
            printf("%d",a);
    }
    else
    {
        for(int i=1;i<=a;i++)
            printf("%d",b);
    }
    return 0;
}


Measured memory_bytes: 256
def check2(X,Y):
    for s in range(0,X+1):
        if(4*X-Y==2*s):
            return True
    return False        


if __name__=="__main__":
    a,b = input().split()
    a = int(a)
    b = int(b)
    if(check2(a,b)):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9184