akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)

int g_bm;

int modl(_LL a)
{
    a %= g_bm;
    if( a < 0 ) a += g_bm * ( 1 - (a + 1) / g_bm );
    return a;
}

int modadd(_LL a, _LL b)
{
    return modl(a + b);
}

int modminus(_LL a, _LL b)
{
    return modl(a - b);
}

int modmul(_LL a, _LL b)
{
    return modl(a * b);    
}

int modinv(_LL a) 
{
    _LL b = g_bm, u = 1, v = 0;
    while (b) 
    {
        _LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    return modl(u);
}

int main()
{
    int n, p;
    cin >> n >> p;
    g_bm = p;
    string s;
    cin >> s;
    int *m = new int[p];
    rep(i, p) m[i] = 0;
    _LL ans = 0;
    if( p == 2 || p == 5 )
    {
        // 10と互いに素でない。
        rep(i, n)
        {
            int cs = (s[i] - '0') % p;
            if( cs == 0 ) ans += i + 1;
        }
    }
    else
    {
        _LL k = 1;
        _LL all = 0;
        _LL diff = 0;
        rep(i, n)
        {
            int cs = (s[i] - '0') % p;
            all = modadd(modmul(all, 10), cs);
            m[diff]++;
            int invk = modinv(k);
//            cout << "all : " << all << " k:" << k << " invk:" << invk << endl;
//            cout << modmul(all, invk) << endl;
            ans += m[modmul(all, invk)];
            diff = modadd(diff, modmul(cs, invk));
            k = modmul(k, 10);
            
//            rep(j, p) cout << j << ":" << m[j] << endl;
//            cout << "ans:" << ans << endl;
        }
    }
    cout << ans << endl;        
}

Measured memory_bytes: 3764
#include <stdio.h>
#include <math.h>
void A(void);
void B(void);
void C(void);
void C2(void);
void D(void);
void E(void);

int main(void){
    C();
    return 0;
}

void A(void){
    int a,b,c,k;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d %d %d",c,a,b);
}

void B(void){
    int n,m,i,k=0;
    double sum=0;
    int array[1000];
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        scanf("%d",&array[i]);
        sum+=array[i];
    }
    for(i=0;i<n;i++){
        if(array[i]>=sum/(4*m))k++;
    }
    if(k>=m){printf("Yes");
    }else{printf("No");}
}

void C(void){
    unsigned long long int a,b,min1,min2,min;
    scanf("%lld %lld",&a,&b);
    min1=a%b;
    min2=b-a%b;
    if(min1<min2){
        min=min1;
    }else{
        min=min2;
    }
    printf("%lld",min);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

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




ll k,sum;

int main() {
	cin >> k;
	REP(i,1, k + 1) {
		REP(j,1, k + 1) {
			REP(m,1, k + 1) {
				sum += gcd(gcd(i, j), m);
			}
		}
	}
	
	cout << sum << endl;

	return 0;
}



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

int arr[100005],ans[100005];

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

        for(int i=2;i<=1e5;i++)
            ans[i]=1e9;
        int n,k; scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
            scanf("%d",&arr[i]);

        ans[1]=0;

        for(int i=2;i<=n;i++){
            for(int j=1;j<=k;j++){
                if(i-j<1) break;
                ans[i]=min(ans[i],(ans[i-j]+abs(arr[i]-arr[i-j])));
            }
        }

        printf("%d",ans[n]);

    return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
ans=0
d=0
for i in range(n):
  ans+=abs(a[i])
  if i==0:
    mini=abs(a[i])
  else:
    mini=min(mini,abs(a[i]))
  if a[i]<0:
    d+=1
    d%=2
  elif a[i]==0:
    d=0
if d==0:
  print(ans)
else:
  print(ans-2*mini)
  

Measured memory_bytes: 64752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N, K;
bool ban[110][110];

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    if (K>N*(N-1)/2-(N-1)) {
        cout << -1 << endl;
        exit(0);
    }
    rep(i, N) rep(j, N) ban[i][j] = false;
    for (int i=1; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            if (K==0) break;
            ban[i][j] = true;
            K--;
        }
    }
    vector<int> u, v;
    rep(i, N) for (int j=i+1; j<N; j++) {
        if (!ban[i][j]) {
            u.pb(i+1);
            v.pb(j+1);
        }
    }
    cout << u.size() << endl;
    rep(i, u.size()) cout << u[i] << " " << v[i] << endl;
}

Measured memory_bytes: 512
n = gets.chomp.to_i
p = gets.chomp.split(' ').map(&:to_i)

counter = 0
for i in 1..(p.count-1-1)
  if p[i-1] < p[i] && p[i] < p[i+1]
    counter += 1
  elsif p[i-1] > p[i] && p[i] > p[i+1]
    counter += 1
  end
end

puts counter

Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=20;
char s[MAXN];
int main()
{
	int n,m,num=0,place=0;
	scanf("%d%d\n",&n,&m);
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;++i)
		if(s[i]=='-') {++num;place=i;}
	if(num==1&&place==n&&m+n+1==len) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
long long INF = 1e18;
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    long long ans = INF;
    for(int i = 0; i < N; i++){
        if(i + K - 1 >= N) break;
        if(a[i] < 0 && a[i + K - 1] > 0) ans = min(ans, abs(a[i]) + abs(a[i + K - 1]) + min(abs(a[i]), abs(a[i + K - 1])));
        else ans = min(ans, max(abs(a[i]), abs(a[i + K - 1])));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

using namespace std;

const double EPS = 1e-10;
const int64_t INF = 1e9;

typedef long long ll;

const ll MOD = 1000000007;

int main()
{
	ll ans[2][4];
	ans[0][0] = 1;
	ans[0][1]=ans[0][2]=ans[0][3]=0;

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

	ll *prv, *nxt;
	prv = ans[0];
	nxt = ans[1];

	for (int i = 0; i < N; ++i) {
		nxt[0] = prv[0] * 8;
		nxt[1] = (prv[1] * 9) % MOD + prv[0];
		nxt[2] = (prv[2] * 9) % MOD + prv[0];
		nxt[3] = (prv[1]+prv[2]) % MOD + ((prv[3] * 10) % MOD);
		for (int j = 0; j < 4; ++j)
			nxt[j] %= MOD;

//		for (int j = 0; j < 4; ++j)
//			printf("%lld ", nxt[j]);
//		printf("\n");
		swap(prv, nxt);
	}

	printf("%lld\n", prv[3]);

	return 0;
}



Measured memory_bytes: 3228
/* Simple Calculator */
/* 20181119 AOJ */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int a, b, ret;
	char opt;

	while(1){
		scanf("%d %c %d", &a, &opt, &b);
		switch(opt){
			case '+' : ret = a + b; break;
			case '-'  : ret = a - b; break;
			case '*'  : ret = a * b; break;
			case '/'  : ret = a / b; break;
			case '?'  : break;
			default  : break;
		}
		if( opt != '?'){
			printf("%d\n", ret);
		}else{
			break;
		}
	 }

	return 0;
}


Measured memory_bytes: 1932
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c,k;
	cin >> a >> b >> c >> k;
	int n = 0;

	//string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);

	for (int i = 0; i < k; i++)
	{
		if (a != 0)
		{
			n++;
			a--;
		}
		else if (b != 0)
		{
			b--;
		}
		else if (c != 0)
		{
			n--;
			c--;
		}
	}


	if (true)
	{
		cout << n << endl;
	}

}

Measured memory_bytes: 3624
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      a: [i64; n]
   }

   let mut l = vec![];
   let mut set = std::collections::BTreeSet::new();
   for x in a {
      if set.remove(&x) {
         l.push(x);
      } else {
         set.insert(x);
      }
   }
   l.sort_by_key(|x| -x);
   if l.len() < 2 {
      println!("0");
   } else {
      println!("{}", l[0] * l[1]);
   }
}


Measured memory_bytes: 6396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		String s = sc.next(), t = sc.next();
		String st = t.substring(0,t.length()-1);
		if(s.length() <= 10 && st.equals(s)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

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


Measured memory_bytes: 32596
import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############

def diff(S, i, T):
    res = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            res += 1
    return res

def solve():
    S = input().rstrip()
    T = input().rstrip()
    res = 10 ** 9
    for i in range(0, len(S)):
        if i + len(T) - 1 >= len(S):
            continue
        res = min(res, diff(S, i, T))
    return res

    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))


Measured memory_bytes: 68176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
vector<vector<char>>v;
ll n,m,k;
bool issafe(ll i,ll j)
{
	vector<vector<char>>v1=v;
	ll x=0;
	while(i>0)
	{
		if(i&1)
		{
			for(ll f=0;f<m;f++)
				v1[x][f]='@';
		}
		i=i>>1;
		x++;
	}
	x=0;
	while(j>0)
	{
		if(j&1)
		{
			for(ll f=0;f<n;f++)
				v1[f][x]='@';
		}
		j=j>>1;
		x++;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
			if(v1[i][j]=='#')
				ans++;
		}
	}
	return ans==k;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	cin>>n>>m>>k;
    	v.assign(n,vector<char>(m));
    	for(ll i=0;i<n;i++)
    	{
    		for(ll j=0;j<m;j++)
    			cin>>v[i][j];
    	}
    	ll rtar=1<<n,ctar=1<<m;
    	ll ans=0;
    	for(ll i=0;i<rtar;i++)
    	{
    		for(ll j=0;j<ctar;j++)
    		{
    			if(issafe(i,j))
    				ans++;
    		}
    	}
    	cout<<ans;
    }
    return 0;
}

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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
double a[60];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n=ini();

    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    double last=a[1];
    for(int i=2;i<=n;i++){
        last = (last+a[i])/2.0;
    }

    printf("%.10f\n", last);


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
using namespace std;
int main(){
   int N,sum=0,flag=0;
   cin >> N;
   int s[N];
   for(int i=0;i<N;i++){
       cin >> s[i];
       sum = sum + s[i];
   }

   sort(s,s+N);
   
   if(sum%10!=0){
       cout << sum << endl;
   }else{
       for(int i=0;i<N;i++){
           if(s[i]%10!=0){
               sum = sum-s[i];
               flag = 1;
               break;
           }
       }
       if(flag==1){
           cout << sum << endl;
       }else{ 
            cout << 0 << endl;
       }
   }
}

Measured memory_bytes: 256
// 7/25 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll money = 1000;
    ll stock = 0;

    for (int i = 0; i < N-1; i++) {
        if (A[i] < A[i+1]) {
            stock += money / A[i];
            money = money % A[i];
        } else if (A[i] > A[i+1]) {
            money += A[i] * stock;
            stock = 0;
        }
    }

    if (stock > 0) {
        // cout << "here?" << endl;
        // cout << A[N-1] << endl;
        money += A[N-1] * stock;
    }

    cout << money << endl;
    return 0;
}

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

int main() {
	string S;
	cin >> S;
	vector<int> v(S.size(),0);
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')v[i]++;
		if (v[i] != 0)v[i] = v[i - 1] + 1;
	}
	cout << *max_element(v.begin(), v.end()) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int N, ans=0;
    string A,B,C;
    cin >> N >> A >> B >> C;
    for (int i = 0;i<N;i++){
        if(A[i]==B[i]&&B[i]==C[i])continue;
        if(A[i]==B[i]){ans++;continue;}
        if(B[i]==C[i]){ans++;continue;}
        if(C[i]==A[i]){ans++;continue;}
        ans=ans+2;
    }
    cout << ans<<endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

ll modpow(ll a, ll n){
  ll ans = 1;
  while(n > 0){
    if(n & 1) ans = ans * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return ans;
}

ll n;
st l;

ll saiki(ll i){
	if(i == n - 1){
		if(l.at(i) == '1') return 3;
		return 1;
	};
	if(l.at(i) == '0') return saiki(i + 1);
	return (2 * saiki(i + 1) + modpow(3, n - 1 - i)) % mod;
}

int main(){
	cin >> l;
	n = l.size();
	cout << saiki(0) << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){

    ll X,money=100,ans = 0;
    cin >> X;
    while(1){
        if(money >= X){
            break;
        }
        ans++;
        money*=1.01;

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


Measured memory_bytes: 3624
n, k = map(int, input().split())
s = [0] * (n+1)
a = [0] * k
for i in range(k):
    d = int(input())
    aa = [int(_) for _ in input().split()]
    a[i] = aa

for i in range(k):
    l = len(a[i])
    for j in range(l):
        s[a[i][j]] += 1

ans = 0
for i in range(1, n+1):
    if s[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9212
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break

    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(int(a/b))


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> W(N);
    ll total = 0;
    Rep (i, N) {
        cin >> W[i];
        total += W[i];
    }

    ll ans = 100000000;

    Rep (i, N) {
        ll T = i;
        ll g1 = 0;
        ll g2 = 0;
        Rep (j, N) {
            if (j <= T) {
                g1 += W[j];
            } else {
                g2 += W[j];
            }
        }
        // cout << "g1=" << g1 << " g2=" << g2 << endl;
        ans = min(ans, abs(g1 - g2));
    }


    cout << ans << endl;


    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e6+10;
vector<int> G[maxn];
int ans;
bool dfs(int x,int ff){
	bool flag=0;
	for(auto v:G[x]) if(v!=ff){
		bool b=dfs(v,x);
		if(flag && b) ans=1;
		flag|=b;
	}
	return flag^1;
}
int main(){
	int n=read();
	REP(i,1,n-1){
		int x=read(),y=read();
		G[x].push_back(y),G[y].push_back(x);
	}
	ans|=dfs(1,0);
	printf("%s\n",ans?"First":"Second");
	return 0;
}


Measured memory_bytes: 26880
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int MOD = 924844033;

void sadd(int &a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}
int add(int a, int b)
{
    sadd(a, b);
    return a;
}
void ssub(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += MOD;
}
int sub(int a, int b)
{
    ssub(a, b);
    return a;
}
int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}
void smul(int &a, int b)
{
    a = mul(a, b);
}


const int N = 2005;
bool used[N];

int dp[N][N][2];
int fact[N];


struct Item
{
    bool fst, l, r;

    Item() : fst(), l(), r() {}

    Item(bool _fst, bool _l, bool _r) : fst(_fst), l(_l), r(_r) {}
};

vector <Item> ord;

int ans[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, k;
    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; i++)
    {
        if (used[i])
            continue;
        for (int j = i; j < n; j += 2 * k)
        {
            used[j] = true;
            ord.push_back(Item(j == i, j >= k, j + k < n));
        }
    }

    fact[0] = 1;
    for (int i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);

    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++)
        for (int j = 0; j <= i; j++)
            for (int t = 0; t <= 1; t++)
            {
                int cur = dp[i][j][t];
                if (cur == 0)
                    continue;
                bool l = ord[i].l;
                if (!ord[i].fst)
                    l &= (t == 0);
                bool r = ord[i].r;

             //   eprintf("i = %d, l = %d, r = %d\n", i, l, r);

                sadd(dp[i + 1][j][0], cur);
                
                if (l)
                    sadd(dp[i + 1][j + 1][0], cur);
                if (r)
                    sadd(dp[i + 1][j + 1][1], cur);
            }

    for (int i = 0; i <= n; i++)
    {
        ans[n - i] = add(dp[n][i][0], dp[n][i][1]);
        smul(ans[n - i], fact[n - i]);
        //eprintf("i = %d : ans[%d] = %d\n", i, n - i, ans[n - i]);
    }

    for (int i = 0; i < n; i++)
        if ((n - i) % 2)
            ssub(ans[n], ans[i]);
        else
            sadd(ans[n], ans[i]);

    printf("%d\n", ans[n]);

	return 0;
}




Measured memory_bytes: 30208
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define int long long
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll INF = 2e18;
ll res = INF;
int n;
vector<ll> c;
vector<string> v, rv;
void dijkstra(){
    priority_queue<pair<ll, pair<string, bool>>, vector<pair<ll, pair<string, bool>>>, greater<pair<ll, pair<string, bool>>>> pq;
    map<pair<string, bool>, ll> dist;
    auto get = [&](pair<string, bool> x)->ll{
        if(dist.find(x) != dist.end()) return dist[x];
        else return INF;
    };
    for(int i = 0; i < n; ++i){
        pq.push({c[i], {v[i], 0}});
        pq.push({c[i], {rv[i], 1}});
        // cout << v[i] << " " << rv[i] << "\n";
        dist[{v[i], 0}] = min(get({v[i], 0}), c[i]);
        dist[{rv[i], 1}] = min(get({rv[i], 1}), c[i]);
    }
    while(!pq.empty()){
        ll cc = pq.top().f;
        pair<string, bool> state = pq.top().s;
        pq.pop();
        if(cc != get(state)) continue;
        for(int i = 0; i < n; ++i){
            string s1 = state.f, s2 = rv[i];
            if(state.s){
                swap(s1, s2);
                s1 = v[i];
            }
            while(sz(s1) && sz(s2) && s1.back() == s2.back()){
                s1.pop_back(); s2.pop_back();
            }
            if(s1 == "" && get({s2, true}) > cc + c[i]){
                dist[{s2, true}] = cc + c[i];
                pq.push({cc + c[i], {s2, true}});
            }
            if(s2 == "" && get({s1, false}) > cc + c[i]){
                dist[{s1, false}] = cc + c[i];
                pq.push({cc + c[i], {s1, false}});
            }
        }
    }
    for(auto i : dist){
        string r = i.f.f;
        reverse(r.begin(), r.end());
        if(r == i.f.f) ckmin(res, i.s);
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n; c.assign(n, 0);
    for(int i = 0; i < n; ++i){
        string s; cin >> s >> c[i];
        rv.pb(s);
        reverse(s.begin(), s.end());
        v.pb(s);
    }
    dijkstra();
    cout << (res == INF ? -1LL : res);
    return 0;
}

Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = ReadString();

            var a = int.Parse(S.Substring(0, 2));
            var b = int.Parse(S.Substring(2, 2));

            switch ((0 < a && a <= 12 ? 1 : 0) << 1 | (0 < b && b <= 12 ? 1 : 0))
            {
                case 0:
                    Out("NA");
                    break;
                case 1:
                    Out("YYMM");
                    break;
                case 2:
                    Out("MMYY");
                    break;
                case 3:
                    Out("AMBIGUOUS");
                    break;
            }
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }
}

Measured memory_bytes: 13140
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

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

  cout << max({a-b,a+b,a*b}) << endl;

  return 0;
}

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

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

ll N;
vll h, a, dp, segmenttree;

void build(ll node, ll start, ll end){
    if(start == end){ segmenttree[node] = dp[start]; return; }
    ll mid = (start+end)>>1;
    build(2*node+1, start, mid);
    build(2*node+2, mid+1, end);
    segmenttree[node] = max(segmenttree[2*node+1], segmenttree[2*node+2]);
    return;
}

ll getmax(ll node, ll start, ll end, ll l, ll r){
    if(start > r or end < l) return mINF;
    if(start >= l and end <= r) return segmenttree[node];
    ll mid = (start+end)>>1;
    return max(getmax(2*node+1, start, mid, l, r), getmax(2*node+2, mid+1, end, l, r));
}

void update(ll node, ll start, ll end, ll idx, ll val){
    if(start > idx or end < idx) return;
    if(start == end and start == idx){ dp[idx] = val; segmenttree[node] = val; return; }
    ll mid = (start+end)>>1;
    update(2*node+1, start, mid, idx, val);
    update(2*node+2, mid+1, end, idx, val);
    segmenttree[node] = max(segmenttree[2*node+1], segmenttree[2*node+2]);
    return;
}

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> N;
    h.resize(N);
    a.resize(N);
    dp.resize(N+1, 0); // dp[i] - son alinan cicek i yukseklige sahip oldugunda o zamana kadarki maximum total value

    segmenttree.resize(4*N);

    for(auto &x: h) cin >> x;
    for(auto &x: a) cin >> x;

    build(0, 0, N+1);
    for(ll f = 0; f < N; ++f) update(0, 0, N+1, h[f], getmax(0, 0, N+1, 0, h[f]-1) + a[f]);
    prn(getmax(0, 0, N+1, 0, N));

    return 0;
}

//cikisir



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

int main(void)
{
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);

        a += b;
        c += d;

        if(a < c)
                puts("Right");
        else if(a > c)
                puts("Left");
        else
                puts("Balanced");

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int wi[100001], vi[100001];
long long dp[105][100005];

long long solve(int n, int w){
    if(n == 0 || w == 0) return 0;
    if(dp[n-1][w] != -1) return dp[n-1][w];
    if(wi[n-1] > w){
        return dp[n-1][w] = solve(n-1, w);
    }
    return dp[n-1][w] = max(solve(n-1,w), solve(n-1,w-wi[n-1])+vi[n-1]);
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,w; cin >> n >> w;
    for(int i = 0; i < n;i++) 
    {
        cin >> wi[i] >> vi[i];

    };
    for(int i = 0; i <= n ; i++){
        for(int j = 0;j <= w ; j++) {
            dp[i][j] = -1;
        }
    }
    cout << solve(n,w) << endl; 
    
    return 0;

}



Measured memory_bytes: 82504
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;
int N = 100;

int main(){
  int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> p[i];
  }
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1;i++){
      j = i+l-1;
      m[i][j] = (1 << 21);
      for(k = i; k <= j-1; k++){
        m[i][j] =min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c,d;
cin>>a>>b>>c>>d;
if((abs(a-b)<=d&&(abs(b-c))<=d)||abs(a-c)<=d){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int64_t pppppow(int64_t a, int64_t b){
  int64_t G = a;
  
  for (int64_t i = 1; i < b; i++){
  	G *= a % 1000000007;
    G %= 1000000007;
  }  
  return G;
}
 
 
int main() {
 
  int64_t A;
  cin >> A;
  int64_t count;
  
  if(A == 1){
    cout << "0" << endl;
  }else if(A == 2){
    cout << "2" << endl;
  }else{
     
  int64_t ans;
    ans = pppppow(10,A) - pppppow(9,A) - pppppow(9,A) + pppppow(8,A);
    ans %= 1000000007;
   cout << (ans + 1000000007) % 1000000007 << endl;
  }
 
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int R, S, P;
  cin >> R >> S >> P;
  string T;
  cin >> T;

  vector<char> H(N);
  for (int i = 0; i < N; i++) {
    if (T.at(i) == 'r') {
      if (i - K >= 0) {
        if (H.at(i - K) != 'p') {
          H.at(i) = 'p';
        } else {
          H.at(i) = 'a';
        }
      } else {
        H.at(i) = 'p';
      }
    } else if (T.at(i) == 's') {
      if (i - K >= 0) {
        if (H.at(i - K) != 'r') {
          H.at(i) = 'r';
        } else {
          H.at(i) = 'a';
        }
      } else {
        H.at(i) = 'r';
      }
    } else if (T.at(i) == 'p') {
      if (i - K >= 0) {
        if (H.at(i - K) != 's') {
          H.at(i) = 's';
        } else {
          H.at(i) = 'a';
        }
      } else {
        H.at(i) = 's';
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (H.at(i) == 'r') {
      sum += R;
    } else if (H.at(i) == 's') {
      sum += S;
    } if (H.at(i) == 'p') {
      sum += P;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512
class Tree():
    def __init__(self):
        self.root = None

    def insert(self, z):
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.p = y

        if not y:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def show(self):
        self.root.inorder()
        print()
        self.root.preorder()
        print()


class Node():
    def __init__(self, key):
        self.key = key
        self.p, self.left, self.right = None, None, None

    def inorder(self):
        if self.left:
            self.left.inorder()
        print(" {}".format(self.key), end="")
        if self.right:
            self.right.inorder()

    def preorder(self):
        print(" {}".format(self.key), end="")
        if self.left:
            self.left.preorder()
        if self.right:
            self.right.preorder()


tree = Tree()
n = int(input())
for _ in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        tree.insert(Node(int(cmd[1])))
    else:
        tree.show()

Measured memory_bytes: 153796
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	vint ans(6,0);
	rep(i,n){
		double t;
		cin>>t;
		if(t>=185.0){
			ans[5]++;
		}
		else{
			rep(j,5){
				if(t<165.0+5.0*j){
					ans[j]++;
					break;
				}
			}
		}

	}
	rep(i,6){
		cout<<i+1<<":";
		rep(j,ans[i]){
			cout<<"*";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
 ll N,M;
const ll limit=50;
vector<ll>a;
vector<ll>b;

bool G[limit][limit];
bool visited[limit];

void dfs(ll v){
  visited[v]=true;
  rep(v2,N){
if(G[v][v2]==true&&visited[v2]==false){
dfs(v2);
}
  }
}

    
int main(){

  cin>>N>>M;
  ll ans=0;
  
  a.resize(M);
  b.resize(M);//int main()外でvectorを定義し、のちにそのサイズが重要になる場合resizeを使う

  
  rep(i,M){
cin>>a[i]>>b[i];
    G[a[i]-1][b[i]-1]=G[b[i]-1][a[i]-1]=true;
  }
  
rep(i,M){
  G[a[i]-1][b[i]-1]=G[b[i]-1][a[i]-1]=false;
  rep(i,N){
visited[i]=false;
  }
  dfs(0);
  bool flag=false;
  
  rep(i,N){
    if(visited[i]==false){
flag=true;
    }
  }

  if(flag){
ans++;
  }
  G[a[i]-1][b[i]-1]=G[b[i]-1][a[i]-1]=true;
}
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main() 
{
    ll n; cin>>n;
    double d; cin>>d;
    int count=0;
    ll x,y;
    double dist;
    while(n--) {
        cin>>x>>y;
        double x2 = x*x;
        double y2 = y*y;
        double dist2 = x2+y2;
        dist = sqrt(dist2);
        if(dist <= d) count++;
    }

    cout<<count<<endl;


    return 0;
}

Measured memory_bytes: 3776
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class ABC178B
    {
        static void Main(string[] args)
        {
            //int x = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long a = long.Parse(str[0]);
            long b = long.Parse(str[1]);
            long c = long.Parse(str[2]);
            long d = long.Parse(str[3]);
            long e = a*c;
            long f = a*d;
            long g = b*c;
            long h = b*d;
            long ans = Math.Max(e,Math.Max(f,Math.Max(g,h)));
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27528
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        
        int count0 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') count0++;
        }
        
        System.out.println(Math.min(count0, s.length()-count0)*2);
    }
}





Measured memory_bytes: 24916
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
Gleft = [A[0]]
Gright = [A[-1]]
for i in range(1,N):
    Gleft.append(gcd(Gleft[-1],A[i]))
    Gright.append(gcd(Gright[-1],A[-1-i]))
Gright = Gright[::-1]
res = max(Gright[1],Gleft[-2])
for i in range(1,N-1):
    res = max(res,gcd(Gleft[i-1],Gright[i+1]))
print(res)

Measured memory_bytes: 16152
// C - Sum of product of pairs
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int MOD = (1e9) + 7;
	int64_t ans = 0, b = 0;
	for(int i=0; i<N; ++i){
		int a; cin>>a;
		ans += a * b % MOD;
		ans %= MOD;
		b += a;
		b %= MOD;
	}
	cout<< (ans + MOD) % MOD <<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;
 
class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
            while (sc.hasNextDouble()) {
                double x = sc.nextDouble();
 
                 double n = Math.ceil(((((x/9.8)*(x/9.8)*4.9)+5)/5));
                System.out.println((int)n);
            }
        } finally {
            sc.close();
        }
    }
}

Measured memory_bytes: 27852
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int INF=0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number=1000000;



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

}


Measured memory_bytes: 3116
S = list(input())
S.append("A")
for j in range(len(S) - 2):
    if (S[j] == S[j + 1]):
        print(j+1, j+2)
        exit()
    if (S[j] == S[j + 2]):
        print(j+1, j+3)
        exit()
else:
    print("-1 -1")


Measured memory_bytes: 3956