akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
}


Measured memory_bytes: 26644
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<fstream>
#include<map>
#include<queue>
#include<stack>
using namespace std;
long long n,m,sum,c[20][20];
long long f[1<<15][15],p[1<<15];
int main(){
	memset(f,-1,sizeof(f));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--,v--;
		sum+=w;
		c[u][v]=w,c[v][u]=w;
	}
	for(int i=0;i<=(1<<n)-1;i++){
		for(int j=0;j<=n-1;j++){
			if(i&(1<<j)){
				for(int k=j+1;k<=n-1;k++){
					if(i&(1<<k)){
						p[i]=p[i]+c[j][k];
					}
				}
			}
		}
	}
	f[1][0]=0;
	for(int i=0;i<=(1<<n)-1;i++){
		for(int j=0;j<=n-1;j++){
			if(f[i][j]==-1){
				continue;
			}
			int x=(((1<<n)-1)^i)|(1<<j);
			for(int k=x;k;k=(k-1)&x){
				f[i|k][j]=max(f[i|k][j],f[i][j]+p[k]);
			}
			for(int k=1;k<=n-1;k++){
				if((!(i&(1<<k)))&&c[j][k]){
					f[i|(1<<k)][k]=max(f[i|(1<<k)][k],f[i][j]+c[j][k]);
				}
			}
		}
	}
	long long ans=100000000000000;
	for(int i=0;i<=(1<<n)-1;i++){
		for(int j=0;j<=n-1;j++){
			if(i&(1<<j)){
				ans=min(ans,sum-f[i][n-1]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4480
import java.util.Scanner;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    final int n = Integer.parseInt(sc.next());
    final String str = sc.next();
    if (n % 2 == 1) {
      System.out.println("No");
      return;
    }

    final String halfStr = str.substring(0, n / 2);
    final String answer = str.equals(halfStr + halfStr) ? "Yes" : "No";
    System.out.println(answer);
  }
}

Measured memory_bytes: 21588
import collections
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
c=collections.Counter(a)
i=0
ans=0
while i<n:
    h=c[a[i]]
    if h>=a[i]:
        ans+=h-a[i]
    else:
        ans+=h
    i+=h
print(ans)

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<string> ori(n), sma(m);
  for (int i = 0; i < n; i++) cin >> ori[i];
  for (int i = 0; i < m; i++) cin >> sma[i];
  for (int i = 0; i <= n - m; i++)
    for (int j = 0; j <= n - m; j++) {
      bool ok = true;
      for (int k = 0; k < m; k++)
        for (int l = 0; l < m; l++) {
          if (ori[i + k][j + l] != sma[k][l]) ok = false;
        }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 250
int parent(int );
int left(int );
int right(int );



int main(){
  int i;
  int n;
  int H[MAX+1];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
  }
  

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(parent(i) >= 1 )printf("parent key = %d, ",H[parent(i)] );
    if(left(i) <= n )printf("left key = %d, ",H[left(i)] );
    if(right(i) <= n )printf("right key = %d, ",H[right(i)] );
    printf("\n");
  }

  
  return 0;
}


int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}




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

int main(){
  int N, M;
  cin >> N;
  vector<string> vec1(N);
  for(int i = 0; i < N; i++){
    cin >> vec1.at(i);
  }
  cin >> M;
  vector<string> vec2(M);
  for(int i = 0; i < M; i++){
    cin >> vec2.at(i);
  }
  vector<int> t(N);
  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
      if(vec1.at(i) == vec1.at(j)){
        t.at(i) += 1;
      }
    }
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      if(vec1.at(i) == vec2.at(j)){
        t.at(i) -= 1;
      }
    }
  }
  int s = 0;
  for(int i = 0; i < N; i++){
    if(t.at(i) > s){
      s = t.at(i);
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
   int N;
    scanf("%d",&N);
    int i,t[N+1],x[N+1],y[N+1];
    int dt,dx,dy,dist;

    t[0] = 0;
    x[0] = 0;
    y[0] = 0;

    for(i = 1;i < N+1;i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
 
    for(i = 1;i < N+1;i++){
        dt = t[i] - t[i-1];
        dx = x[i] - x[i-1];
        dy = y[i] - y[i-1];

        dist = abs(dx) + abs(dy);
        
        if(dist > dt){
            printf("No");
            return 0;
        }
        
        if(dist % 2 != dt % 2){
            printf("No");
            return 0;
        }
        
    }
 
        printf("Yes\n");

    return 0;
}

Measured memory_bytes: 1280
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [a,b,c]<- map read.words <$> getLine :: IO [Int]
    print $ max 0 (c-(a-b))


-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long long> x(n);
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i){
      x[j-1]++;
    }
  }
  long long ans=0;
  for(int i=1;i<=n;i++){
    ans+=i*x[i-1];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 81408
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n, k;
    std::scanf("%d %d", &n, &k);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        std::scanf("%d", &x);
        ans += std::min(x * 2, (x - k) * 2 < 0 ? (k - x) * 2 : (x - k) * 2);
    }
    std::printf("%d\n", ans);
    return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> t(n+1,0), x(n+1,0), y(n+1,0);
	for (int i=1; i<=n; i++) {
		cin>>t[i]>>x[i]>>y[i];
	}
	for (int i=1; i<=n; i++) {
		int u=t[i]-t[i-1], v=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if(u%2!=v%2) {
			cout<<"No\n";
			return 0;
		}
		if(v>u) {
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n, tmp;
    cin >> n;
    tmp=n/1.08;
    while(1){
        if(floor(tmp*1.08)==n){
            cout<<tmp<<endl;
            break;
        }else if(floor(tmp*1.08)>n){
            cout<<":("<<endl;
            break;
        }
        tmp++;
    }
}


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

using namespace std;

int main(){

    int N;
    string a;

    cin >> N >> a;

    for(int i=0;i<a.size();i++){
        a[i]+=N;
        if(a[i]>'Z') a[i]-=26;
    }

    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    n = 1
    for a in A:
        if a == n:
            n += 1

    if n == 1:
        print(-1)
    else:
        print(N - n + 1)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int ll;

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

  ll n;
  cin >> n;
  vector < ll > a(n + 1), p(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  p[0] = 0;

  ll cnt = 0;
  for(int i = 1; i <= n; i++){
    if(i % 2){
      if(p[i - 1] + a[i] > 0){
        p[i] = p[i - 1] + a[i];
        continue;
      }
      ll c = 1 - a[i] - p[i - 1];
      cnt += c;
      p[i] = c + a[i] + p[i - 1];
    }else{
      if(p[i - 1] + a[i] < 0){
        p[i] = p[i - 1] + a[i];
        continue;
      }
      ll c = 1 + a[i] + p[i - 1];
      cnt += c;
      p[i] = p[i - 1] + a[i] - c;
    }
  }
  ll ans = cnt;

  cnt = 0;
  for(int i = 1; i <= n; i++){
    if(i % 2 == 0){
      if(p[i - 1] + a[i] > 0){
        p[i] = p[i - 1] + a[i];
        continue;
      }
      ll c = 1 - a[i] - p[i - 1];
      cnt += c;
      p[i] = c + a[i] + p[i - 1];
    }else{
      if(p[i - 1] + a[i] < 0){
        p[i] = p[i - 1] + a[i];
        continue;
      }
      ll c = 1 + a[i] + p[i - 1];
      cnt += c;
      p[i] = p[i - 1] + a[i] - c;
    }
  }

  ans = min(ans, cnt);
  cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <climits>

using p2 = std::pair<int, int>;


// B = 0, W = 1
int main() {
    int n;
    std::cin >> n;
    std::vector<int> bs(n), ws(n);
    for (int i = 0; i < 2 * n; ++i) {
        char t;
        int k;
        std::cin >> t >> k;
        k--;
        if(t == 'W') ws[k] = i;
        else bs[k] = i;
    }
    std::vector<std::vector<int>> bw(n, std::vector<int>(n+1));
    std::vector<std::vector<int>> wb(n, std::vector<int>(n+1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            bw[i][j + 1] = bw[i][j] + (bs[i] < ws[j]);
            wb[i][j + 1] = wb[i][j] + (ws[i] < bs[j]);
        }
    }
    for (int i = 0; i < n; ++i) {
        int invb, invw;
        invb = invw = 0;
        for (int j = 0; j < i; ++j) {
            if(bs[i] < bs[j]) invb++;
            if(ws[i] < ws[j]) invw++;
        }
        for (int j = 0; j < n+1; ++j) {
            bw[i][j] += invb;
            wb[i][j] += invw;
        }
    }

    std::vector<std::vector<int>> dp(n+1, std::vector<int>(n+1, INT_MAX));

    dp[0][0] = 0;
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < n + 1; ++j) {
            if(i < n) dp[i+1][j] = std::min(dp[i+1][j], dp[i][j] + bw[i][j]);
            if(j < n) dp[i][j+1] = std::min(dp[i][j+1], dp[i][j] + wb[j][i]);
        }
    }

    std::cout << dp[n][n] << std::endl;
}

Measured memory_bytes: 47360
#include<stdio.h>
int main()
{
  int H,W;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0 && W==0) break;
    int i,j;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(i%2){
	  if(j%2) printf("#");
	  else printf(".");
	}else{
	  if(j%2) printf(".");
	  else printf("#");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    edge = []
    for i in range(1, n):
        edge.append([1, i + 1])

    total = ((n - 1) * (n - 2)) // 2
    if k > total:
        print(-1)
        exit()

    diff = total - k
    while diff:
        for i in range(1, n):
            for j in range(i + 1, n):
                edge.append([i + 1, j + 1])
                diff -= 1
                if diff == 0:
                    break
            else:
                continue
            break

    print(len(edge))
    for res in edge:
        print(*res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9444
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,f[100010],w[100010],c[100010],v;
int main()
{
	cin>>n>>v;
	for(int i=0;i<n;i++)
		cin>>w[i]>>c[i];
	for(int i=0;i<n;i++)
		for(int j=v;j>=w[i];j--)
			f[j]=max(f[j],f[j-w[i]]+c[i]);
	cout<<f[v]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int N,K;
  int d[101];         //インデックス番号に対応したお菓子が何個あるかを格納する
  int kosu[101];      //iが持ってるお菓子の管理
  int dare[101][101];
  int ans = 0;
  
  cin >> N >> K;
  for(int i = 1;i <= K;i++){
    cin >> d[i];
    
    for(int j = 1;j <= d[i];j++){
      cin >> dare[i][j];
      kosu[dare[i][j]] = 1;
    }
    
  }
  
  
  for(int k = 1; k<= N;k++){
    if(kosu[k] == 0){
      ans++;
    }
  }
  
  
  cout << ans;
  
  
}

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


#define gc getchar
#define pc putchar

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
*/

/*
        two functions for policy based data structure. it is

                find_by_order() and order_of_key().

        The first returns an iterator to the k-th largest element (counting from zero),
        the second returns the number of items in a set that are strictly smaller than our item

*/

#define vi vector<int>
#define si set<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Rep(i,x,y) for(int i=x;i<=y;i++)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt","w", stdout)
#define sz size()
#define dbg(x) printf("yo is %d!\n",x)
#define dbg2(x,y) printf("yo is %d! and %d!\n",x,y)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)

//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
//int dx[] = { -1, -1,  0, 1, 1, 1,  0, -1 };
//int dy[] = {  0, -1, -1, -1,  0, 1, 1, 1 };
//int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
//int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

//functions

//i64 gcd(i64 a,i64 b){if(!b)return a;return gcd(b,a%b);}

//inline void fastRead(i64 *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}

//inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}

//i64 bigmod(i64 num,i64 n){if(!n)return 1;i64 x=(bigmod(num,n/2)*bigmod(num,n/2))%mod;if(n%2)x=(x*num)%mod;return x;}

//i64 modinverse(i64 num){return bigmod(num,mod-2);}

//void combination(int pos,int last){if(pos==k+1){for(int i=1;i<=k;i++)cout << tem[i];cout << endl;return;}
//for(int i=last+1;i<=n-k+pos;i++){tem[pos] = num[i-1];combination(pos+1,i);}}
//i64 power(i64 value, i64 base){i64 result = 1;For(i,base)result *= value;return result;}
//int Set(int N,int pos){return N = (1<<pos);}
//int reset(int N,int pos){return N &= (~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}

//typedef tree< int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > Set;

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2)
        cout << "Borys";
    else
        cout << "Alice";

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
const ll MOD=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b;cin>>a>>b;
    if(a>b)a-=1;
    cout<<a;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define MAX 1024

int N, M;
int henNum[MAX];
int *hens[MAX];

int acount;
int answer[MAX];

int pcount[MAX];
int *pointed[MAX];
int next[MAX];
int visited[MAX];
int avisited[MAX];

int dfs(int cur, int depth) {
	int i;
	int* backup;
	int maxdepth = 0, maxnode = 0;
	visited[cur] = depth;
	avisited[cur] = 1;
	/* ショートカット (これまでのノードからこのノードにおいでおいでする) */
	backup = malloc(sizeof(int) * (pcount[cur] + 1)); /* 0要素を防ぐ(1要素以上確保) */
	if (backup == NULL) exit(3);
	for (i = 0; i < pcount[cur]; i++) {
		backup[i] = next[pointed[cur][i]];
		next[pointed[cur][i]] = cur;
	}
	/* とどめをさせるならさす */
	for (i = 0; i < henNum[cur]; i++) {
		int hen = hens[cur][i];
		/* 一番近いところに飛べる辺を使う */
		if (next[hen] != 0 && visited[hen] > maxdepth) {
			maxdepth = visited[hen];
			maxnode = hen;
		}
		/* ここから行けるよ */
		/* どうせ失敗したら終了するのでバックアップ省略 */
		pointed[hen] = realloc(pointed[hen], sizeof(int) * (pcount[hen] + 1));
		if (pointed[hen] == NULL) exit(3);
		pointed[hen][pcount[hen]++] = cur;
	}
	/* とどめをさした */
	if (maxnode > 0) {
		next[cur] = maxnode;
		free(backup);
		return cur;
	}
	/* 進む */
	for (i = 0; i < henNum[cur]; i++) {
		int res;
		next[cur] = hens[cur][i];
		res = dfs(hens[cur][i], depth + 1);
		if (res != 0) {
			free(backup);
			return res; /* 成功(戻さない) */
		}
	}
	/* 失敗 */
	next[cur] = 0;
	visited[cur] = 0;
	for (i = 0; i < pcount[cur]; i++) {
		next[pointed[cur][i]] = backup[i]; /* このノードは外れるので戻す */
	}
	free(backup);
	return 0;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		int A, B;
		if (scanf("%d%d", &A, &B) != 2) return 1;
		/* メモリリークしてもどうせ終了するのでバックアップを省略 */
		hens[A] = realloc(hens[A], sizeof(int) * (henNum[A] + 1));
		if (hens[A] == NULL) return 2;
		hens[A][henNum[A]++] = B;
	}

	for (i = 1; i <= N; i++) {
		if (!avisited[i]) {
			int j;
			int res = dfs(i, 1);
			if (res != 0) {
				int cur = res;
				answer[0] = cur;
				acount = 1;
				for (;;) {
					cur = next[cur];
					if (cur == res) break;
					if (cur == 0) {
						puts("error!");
						return 0; /* REにならないように0を返す */
					}
					answer[acount++] = cur;
				}
				printf("%d\n", acount);
				for (j = 0; j < acount; j++) {
					printf("%d\n", answer[j]);
				}
				/* どうせ終了するのでfreeは省略 */
				return 0;
			} else {
				for (j = 1; j <= N; j++) {
					pcount[j] = 0;
					free(pointed[j]);
					pointed[j] = NULL;
				}
			}
		}
	}

	/* どうせ終了するのでfreeは省略 */
	puts("-1");
	return 0;
}

/*
6 8
1 2
1 3
2 3
2 6
3 4
4 6
4 5
5 2

6 9
1 2
1 3
2 3
2 4
2 6
3 4
4 6
4 5
5 2

4 4
1 2
3 1
3 4
4 3

*/


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

LL calc(LL x) {
    return x*x*x*x*x;
}

void run_case() {
    LL x, a, b;
    cin >> x;
    for(a = -118; a <= 119; ++a) {
        for(b = -119; b <= 118; ++b) {
            LL tmp = calc(a) - calc(b);
            if(tmp == x) {
                cout << a << " " << b;
                return;
            }
        }
    }
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3656
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

from fractions import gcd
from functools import reduce

#list
def gcd_list(numbers):
    return reduce(gcd, numbers)

n=ii()
arr=limii()
print(gcd_list(arr))


Measured memory_bytes: 87788
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 1e5 + 10;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
int n, m;
int p[N];

int par(int u) {
  return p[u] == u ? u : p[u] = par(p[u]);
}

void join(int u , int v) {
  p[par(u)] = par(v);
}

bool sameset(int u , int v) {
  return par(u) == par(v);
}

int main() {
  for (int i = 1 ; i < N ; i++) p[i] = i;
  in(n); in(m);
  for (int i = 0, u, v ; i < m ; i++) {
    in(u); in(v);
    join(u , v);
  }
  set <int> s;
  for (int i = 1 ; i <= n ; i++) {
    s.insert(par(i));
  }
  printf("%lu\n" , s.size() - 1);
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 8128
def solve():
    def gcd(x,y):
        while y != 0:
            x , y = y , x % y
        return x

    A,B,C,D = map(int ,input().split())
    A -= 1
    gcd_val = gcd(C , D)
    lcm_val = C * D // gcd_val
    ReduceFromB = B - (B // C + B // D - B // lcm_val)
    ReduceFromA = A - (A // C + A // D - A // lcm_val)
    print(ReduceFromB - ReduceFromA)

solve()

Measured memory_bytes: 3060
from fractions import gcd
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a,b = map(lambda x : int(x),input().split())
ko = gcd(a,b)
if ko == 1 :
    print(1)
else :
    list = factorize(ko)
    print(len(set(list)) + 1)


Measured memory_bytes: 5204
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
//input power
int a,b;

int main(){
	cin >> a >> b;
	int ans = 0;
	for(int i = a ; i<=b ; i++){
		string N = to_string(i);
			if(N.at(0)==N.at(4)&&N.at(1)==N.at(3)) ans ++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n,m=input().split()
n=int(n)
m=int(m)
a=[int(i) for i in input().split()]

sum=0
for i in range(n):
    sum+=a[i]

able=0
for ai in a:
    if ai>=sum*(1/(4*m)):
        able+=1

if able>=m:
    print('Yes')
else:
    print('No')


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

vector<int64> Partition2(int64 h, int64 w) {
  if (h % 2 == 0 || w % 2 == 0) return  {h * w / 2, h * w / 2};
  if (h > w) swap(h, w);
  return {h * (w / 2), h * (w / 2 + 1)};
}

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

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  int64 h, w;
  cin >> h >> w;

  int64 ans = INT64_MAX;
  for (int64 y = 1; y <= h - 1; y++) {
    vector<int64> ss = Partition2(h - y, w);
    ss.push_back(y * w);
    sort(ss.begin(), ss.end());
    // cout << "y: " << y << ss << endl;
    UpdateMin(ans, ss[2] - ss[0]);
  }
  for (int64 x = 1; x <= w - 1; x++) {
    vector<int64> ss = Partition2(h, w - x);
    ss.push_back(h * x);
    sort(ss.begin(), ss.end());
    UpdateMin(ans, ss[2] - ss[0]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class Program
{
    public static void Main()
    {
        var mod = 1000000007;
        var n = Int64.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var total = new BigInteger(1);
        bool isSuccess = true;
        Array.Sort(A);
        for (int i=0; i < n; ++i)
        {
            total *= A[i];
            if(1000000000000000000 < total)
            {
                isSuccess = false;
                break;
            }
        }
        var ans = isSuccess ? total : -1;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 48944
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

struct UnionFind{
  vector<int> p;
  vector<int> sz;
  UnionFind(int n){
    p.resize(n, -1);
    sz.resize(n, 1);
  }

  int find(int x){
    if(p[x] == -1)return x;
    else return p[x] = find(p[x]);
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    sz[y] += sz[x];
    p[x] = y;
  }

  int size(int x){
    return sz[find(x)];
  }
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<int> fr(n, 0);
  vector<vector<int>> block(n);
  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ++fr[a];
    ++fr[b];
    uf.unite(a, b);
  }
  for(int i = 0; i < k; ++i){
    int c, d;
    cin >> c >> d;
    --c;
    --d;
    block[c].push_back(d);
    block[d].push_back(c);
  }

  for(int i = 0; i < n; ++i){
    int ans = uf.size(i) - fr[i] - 1;
    for(int b : block[i]){
      if(uf.find(i) == uf.find(b))--ans;
    }
    cout << ans << " ";
  }
  return 0;
}


Measured memory_bytes: 7552
/*input
10 10
3 1 4 1 5 9 2 6 5 3
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 998244353
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

ll dp[3001][3001];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n,s;
	cin>>n>>s;
	ll a[n];
	rep(i,0,n)cin>>a[i];
	ll ans=0;
	rep(i,0,n+1)rep(j,0,s+1)dp[i][j]=0;
	dp[0][a[0]]=1;
	ans+=((dp[0][s]*n)%M)%M;
	rep(i,1,n){
		ll k=a[i];
		rep(j,0,s+1)dp[i][j]=dp[i-1][j];
		dp[i][k]+=(i+1);
		dp[i][k]%=M;
		for(j=1;j+k<s+1;j++){
			dp[i][j+k]+=dp[i-1][j];
			dp[i][j+k]%=M;
		}
		ans+=((((dp[i][s]-dp[i-1][s]+M)%M)*(n-i))%M);
		ans%=M;
		//rep(j,0,s+1)cout<<dp[i][j]<<" ";
		//cout<<endl;
	}
	cout<<ans<<endl;
	return 0;
}




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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c && a <= 100 && a >= 0 && b <= 100 && b >= 0 && c <= 100 && c >= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
<>=~$";$s+=$_ for@_=glob<>;printf sort{$b-$a}grep{$d=$_;$t=0;$t+=$_ for@A=sort{$b-$a}map$_%$d,@_;$t-=$_ for@A[0..--$t/$d];$t<$'}map$s%$_?():($_,$s/$_),1..3e4

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
const int N=5*1e6;
const int M=1e9+7;

int mod(int n){
    n%=M;
    return (n+M)%M;
}

int power(int a,int b){
    int ans=1;
    while(b>0){
        if(b&1)
            ans=mod(ans*a);
        a=mod(a*a);
        b/=2;
    }
    return ans;
}

int f[N],invf[N];
void fact(){
    f[0]=f[1]=1;
    for(int i=2;i<N;i++)
        f[i]=mod(f[i-1]*i);
    invf[N-1]=power(f[N-1],M-2);
    for(int i=N-1;i>0;i--)
        invf[i-1]=mod(invf[i]*i);
}

int nCr(int n,int r){
    int ans=f[n];
    ans=mod(ans*invf[r]);
    ans=mod(ans*invf[n-r]);
    return ans;
}

int32_t main() 
{ 
    boost;
    fact();
    int r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    int ans=0;
    for(int i=r1;i<=r2;i++){
        ans+=mod(nCr(i+c2+1,i+1)-nCr(i+c1,i+1));
        ans=mod(ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 78336
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m;
    cin>>n>>m;
    VL h(n);
    REP(i,n){
        cin>>h[i];
    }
    vector<VL> links(n);
    VL good(n,1);
    REP(i,m){
        LL a,b;
        cin>>a>>b;
        a--;
        b--;
        links[a].PB(b);
        links[b].PB(a);
        if(h[a] > h[b]){
            good[b] = 0;
        }
        else if(h[a] < h[b]){
            good[a] = 0;
        }
        else {
            good[a] = good[b] = 0;
        }
    }
    LL ans = 0;
    REP(i,n){
        if(good[i] == 1)ans++;
    }
    PUTS(ans);
}

Measured memory_bytes: 10592
A, B, C = list(map(int, input().split()))
K = int(input())
res = 0

while True:
  if B <= A:
    B *= 2
    res += 1
  else:
    break
    
while True:
  if C <= B:
    C *= 2
    res += 1
  else:
    break

if res <= K:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()





int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll y = x % d;
    if (y < 0) y += d;
    ll z = abs(x - y);
    if (z / d > k) {
        ll ans;
        if (x > 0) {
            cout << abs(x - d * k) << endl;
        } else if (x < 0) {
            cout << abs(x + d * k) << endl;
        }
        exit(0);
    }
    ll a = k - z / d;
    if (a % 2 == 0) {
        cout << abs(y) << endl;
    } else {
        cout << abs(y - d) << endl;
    }
}



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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, m;
int label[200005];
int con[200005][2];

vector<int> edge[200005];
queue<int> del;

bool survive[200005];

map<pair<int, int>, bool> edgelist;

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++){
		char c;
		scanf(" %c", &c);
		label[i] = (c - 'A');
	}
	for(int i = 1; i <= m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		if(a > b){
			swap(a, b);
		}
		if(edgelist.count({a, b})){
			continue;
		}
		edgelist[{a, b}] = true;
		
		edge[a].push_back(b);
		con[a][label[b]]++;
		if(a != b){
			edge[b].push_back(a);
			con[b][label[a]]++;
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(con[i][0] == 0 || con[i][1] == 0){
			del.push(i);
			survive[i] = false;
		}else{
			survive[i] = true;
		}
	}
	while(!del.empty()){
		int cur = del.front();
		del.pop();
		for(auto to: edge[cur]){
			if(!survive[to]){
				continue;
			}
			con[to][label[cur]]--;
			if(con[to][label[cur]] == 0){
				survive[to] = false;
				del.push(to);
			}
		}
	}
	for(int i = 1; i <= n; i++){
		if(survive[i]){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 24960
#include<stdio.h>

int main(void){

    int N,i;
    long int ans = 0;

    scanf("%d",&N);
    for(i = 0;i <= N;i++){
        if(i % 3 != 0){
            if(i % 5 != 0){
                ans += i;
            }
        }
    }

    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
object Main extends App {

  import scala.io.StdIn._
  println(
    countFlip(readLine.trim.toList)
  )
  def countFlip(str: List[Char]): Int = {
    (str.map{
      case '(' ⇒ ')'
      case ')' ⇒ '('
      case c ⇒ c
    }.reverse.zip(str).count{case (a, b) ⇒ a != b} + 1) / 2
  }
}



Measured memory_bytes: 43992
import sys
input = sys.stdin.readline

k, q = map(int, input().split())
d = tuple(map(int, input().split()))


def query(n, x, m):
    dd = tuple(di % m for di in d)
    ans = n - 1

    a0 = a1 = x
    for i in range(k):
        a1 += (((n - 1) - (i + 1)) // k + 1) * dd[i]
        if dd[i] == 0:
            ans -= ((n - 1) - (i + 1)) // k + 1

    ans -= (a1 // m) - (a0 // m)

    return ans


for _ in range(q):
    n_i, x_i, m_i = map(int, input().split())
    ans_i = query(n_i, x_i, m_i)
    print(ans_i)


Measured memory_bytes: 74972
#include <string>
#include <iostream>

using namespace std;

const int LETTERS_IN_ALPHABET = 'z' - 'a' + 1;

char shiftLetter (char letter, int ammount) {
        int letterNumber = letter - 'a';

        letterNumber = (letterNumber + ammount) % LETTERS_IN_ALPHABET;
        return letterNumber + 'a';
}

int main () {
        string text;
        cin >> text;

        int k;
        cin >> k;

        for (int i = 0; i < text.length(); i++) {
                int bestShift = ('z' - text[i] + 1) % LETTERS_IN_ALPHABET;
                if (k >= bestShift) {
                        k -= bestShift;
                        text[i] = 'a';
                }
        }

        text[text.length() - 1] = shiftLetter(text[text.length() - 1], k);

        cout << text << endl;

        return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int a[100005],b[100005],c[100005];
int main()
{
 int n,sum=0;
 int i;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
for(i=1;i<=n;i++)
 {
     sum+=a[i];
     b[i]=sum;
 }
 for(i=1;i<=n;i++)
 {
     c[i]=abs(b[i]-(sum-b[i]));
 }
  sort(c+1,c+n+1);
  printf("%d\n",c[1]);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;

    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;


    } else if (S == "Rainy") {
        cout << "Sunny" << endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}
ll ANS=0;
vector<ll> V; 

vector<ll> divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

void dfs(ll X,ll P){
  if(P==1){
    ANS++;
    return;
  }
  if(X%P==0){
    dfs(X/P,P);
  }
  else{
    if(X%P==1){
      ANS++;
    }
    return;
  }
}

int main(){
  ll N;
  cin >> N;
  V=divisor(N);
  Rep(i,1,V.size()){
    dfs(N,V[i]);
  }
  V.clear();
  V=divisor(N-1);

  cout << ANS+V.size()-1 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define INF 1e9+7
using namespace std;
typedef long long int ll;

int main() {

	int a, b;
	cin >> a >> b;

	if (a + b == 15) {
		cout << '+' << endl;
	}
	else if (a*b == 15) {
		cout << '*' << endl;
	}
	else {
		cout << 'x' << endl;
	}

	return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define l_ength size
typedef long long ll;
typedef pair<int, int> P;
vector<P> v,u;

int a[555][555];

int main(void){
int h, w, i, j, n=0,x,y,p,c=0;
bool flag=false;
cin >> h >> w;
for(i=0;i<h;++i){
for(j=0;j<w;++j){
cin >> a[i][j];
c+=a[i][j]%2;
}
}
c /= 2; c *= 2;
for(i=0;i<h;++i){
if(!c){break;}
for(j=0;j<w;++j){
if(!c){break;}
if(i%2){ p = w-j-1; }else{ p = j; }
if(flag){
v.push_back(P(x,y));
u.push_back(P(i,p));
++n;
}
if(a[i][p]%2){
flag = (!flag);
c-=1;
}
x = i; y = p;
}
}
cout << n << endl;
for(i=0;i<n;++i){
cout << (v[i].first+1) << " " << (v[i].second+1) << " " << (u[i].first+1) << " " <<  (u[i].second+1) << endl;
}
return 0;
}


Measured memory_bytes: 5356
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c,d,g,T;
main(){
    scanf("%lld",&T);
    while(T--){
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        g=__gcd(d, b);
        if(a<b || d<b || (a-(a-c-1)/g*g)-b<0) cout<<"No\n";else cout<<"Yes\n";
    }
}


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

using namespace std;

int main(){
        int a,b,c;
        cin >> a >> b >> c;

        if (a == b && a != c){
                cout << "Yes" << endl;
        }
        else if (a == c && a != b){
                cout << "Yes" << endl;
        }
        else if (b == c && c != a){
                cout << "Yes" << endl;
        }
        else {
                cout << "No" << endl;
        }

        return 0;
}

Measured memory_bytes: 3620
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]

    x_ret = min(refrigerators)
    y_ret = min(microwaves)
    ret = x_ret + y_ret
    for x, y, c in tickets:
        p = refrigerators[x - 1] + microwaves[y - 1] - c
        ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38436
using System;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int K = int.Parse(str[1]);
            string S = Console.ReadLine();
            char[] C = new char[N];
            C = S.ToCharArray();
            /*
            while (K > 0)
            {
                int l = 0, r = 0, tmpflag = 0;
                for (int i = 0; i < N-1; i++)
                {
                    //Console.WriteLine($"i = {i}");
                    if (C[i] != C[i+1] && tmpflag == 0)
                    {
                        //Console.WriteLine("aaa");
                        tmpflag = 1;
                        l = i;
                        i++;
                        continue;
                    }
                    if(C[i] != C[i + 1] && tmpflag == 1)
                    {
                        //Console.WriteLine("bbb");
                        r = i;
                        Rotation(C, l + 1, r);
                        tmpflag = 2;
                        K = K - 1;
                        break;
                    }
                }
                if(tmpflag == 1)
                {
                    Rotation(C, l + 1, N);
                    break;
                }
                if (tmpflag == 0) break;
            }
            */
            int count = 0;
            for(int i = 0; i < N-1; i++)
            {
                if (C[i] != C[i + 1]) count++;
            }
            int ans = evaluation(C, N);
            //Console.WriteLine(ans);
            if (count / 2 >= K) ans = ans + K * 2;
            else ans = ans + count;
            // Console.WriteLine(C);
            Console.WriteLine(ans);


        }
        public static int evaluation(char[] array, int N)
        {
            int count = 0;
            for(int i = 0; i < N-1; i++)
            {
                if (array[i] == array[i + 1]) count++;
            }
            return count;
        }
        public static void Rotation(char[] array, int l, int r)
        {
            int len = r - l + 1;
            char tmp = 'L';
            if (array[l] == 'R') tmp = 'L';
            else tmp = 'R';
        //   Console.WriteLine($"{l},{r},{len}");
            for (int i = 0; i < len; i++)
            {
                array[l + i] = tmp;
            }
        }
    }

    
}

/*
int a, b, c;
a = int.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = int.Parse(str[1]);
string S = Console.ReadLine();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力

string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
 */


Measured memory_bytes: 11616