akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int ans = INT_MAX;
int N, A, B, C;
void dfs(queue<int> l, int a, int b, int c, int mp) {
    if (l.empty()) {
        if (a != 0 && b != 0 && c != 0) {
            mp += abs(A-a)+abs(B-b)+abs(C-c);
            ans = min(ans, mp);
        }
    } else {
        int tmp = l.front();
        l.pop();
        dfs(l, a, b, c, mp);
        dfs(l, a+tmp, b, c, mp+10);
        dfs(l, a, b+tmp, c, mp+10);
        dfs(l, a, b, c+tmp, mp+10);
    }
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    queue<int> L;
    int tmp;
    for (int i = 0; i<N; i++) {
        cin >> tmp;
        L.push(tmp);
    }
    dfs(L, 0, 0, 0, -30);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string stringify(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}

int main() {
  for (;;) {
    int m, n;
    cin >> m >> n;
    if (!m && !n) return 0;
    bool ps[1000];
    fill(ps, ps+m, true);
    for (int i = 1, j = 0, p = m; i <= n; i++) {
      string s;
      cin >> s;
      if (p == 1) continue;
      while (!ps[j]) {
        j++;
        j %= m;
      }
      if (i % 15 == 0 && s != "FizzBuzz" ||
          i % 15 != 0 && i % 3 == 0 && s != "Fizz" ||
          i % 15 != 0 && i % 5 == 0 && s != "Buzz" ||
          i % 3 != 0 && i % 5 != 0 && s != stringify(i)) {
        ps[j] = false;
        p--;
      }
      j++;
      j %= m;
    }
    int s = 0;
    while (!ps[s]) s++;
    cout << s + 1;
    for (int i = s + 1; i < m; i++)
      if (ps[i])
        cout << ' ' << i + 1;
    cout << endl;
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

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

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

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

	int ans=0;
	for(int i=2;i*i<=N;i++){
		int cnt=0;
		while(N%i==0){
			N/=i;
			cnt++;
		}

		for(int j=1;j<=cnt;j++){
			ans++;
			cnt-=j;
		}
	}

	if(N!=1)ans++;
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double mod;
    int  n;
    cin>>n;
    int no[100000];
    for(int i=0;i<n;i++)
    {
        cin>>no[i];

    }
    sort(no,no+n);
     mod =no[0];
    for(int i=1;i<n;i++)
    {
        mod=(mod+no[i])/2.0;
    }
    printf("%0.14lf\n",mod);
   return 0;
}


Measured memory_bytes: 256
// C++ program to find LCM of two numbers 
#include <iostream> 
using namespace std; 
// Recursive function to return gcd of a and b 
class gfg 
{ 
public : long long gcd(long long a, long long b){ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 


// Function to return LCM of two numbers 
long long lcm(long long a, long long b) 
{ 
	return (a*b)/gcd(a, b); 
} 
} ; 
// Driver program to test above function 
int main() 
{ 
	gfg g; 
	long long a , b;
	cin>>a>>b;
	cout<<g.lcm(a, b); 
	return 0; 
} 


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

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

  string x = n.substr(n.length()-1,1);
  if (x == "3") cout << "bon" << endl;
  if (x == "0" || x == "1" || x == "6" || x == "8") cout << "pon" << endl;
  if (x == "2" || x == "4" || x == "5" || x == "7" || x == "9") cout << "hon" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  string S;
  cin >> S;
  string o = S;
  REVERSE(S);
  if (o != S) {
    debug(1);
    COUT("No");
    return 0;
  }

  string sub1 = S.substr(0, (S.size() - 1) / 2);
  string sub1r = sub1;
  REVERSE(sub1r);
  debug(sub1);
  debug(sub1r);
  if (sub1 != sub1r) {
    debug(2);
    COUT("No");
    return 0;
  }

  string sub2 = S.substr((S.size() + 3) / 2 - 1, S.size() - 1);
  string sub2r = sub2;
  REVERSE(sub2r);
  debug(sub2);
  debug(sub2r);
  if (sub2 != sub2r) {
    debug(3);
    COUT("No");
    return 0;
  }
  COUT("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,k,ans=0;
  cin>>n>>k;
  ans=n-k+1;
  cout<<ans<<"\n";
  return 0;
}

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

int main(){
	string s1, s2;
	cin >> s1 >> s2;
	bool res = false;
	if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) res = true;
	string ans = (res)? "YES": "NO";
	cout << ans << endl;
}

Measured memory_bytes: 256
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if deep[x] > deep[y]:
            par[x] += par[y]
            par[y] = x
        elif deep[x] < deep[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            deep[x] += 1
        return True
def same(x,y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
n = int(input())
par = [-1]*n
deep = [1]*n
p = []
edge = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i])
p.sort(key=lambda x:x[0])
for i in range(n-1):
    x_0,_,j=p[i]
    x_1,_,k=p[i+1]
    edge.append([x_1-x_0,j,k])
p.sort(key=lambda x:x[1])
for i in range(n-1):
    _,y_0,j=p[i]
    _,y_1,k=p[i+1]
    edge.append([y_1-y_0,j,k])
edge.sort()
ans = 0
for i in range(len(edge)):
    cost,u,v = edge[i]
    if not same(u,v):
        unite(u,v)
        ans+=cost
print(ans)

Measured memory_bytes: 126708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    if(s == "Sunny")    cout << "Cloudy";
    if(s == "Cloudy")   cout << "Rainy";
    if(s == "Rainy")    cout << "Sunny";
    return 0;
}


Measured memory_bytes: 764
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(4, 5), 10)

    def test_2(self):
        self.assertEqual(think(7, 3), 11)


def solve():
    h, w = read()
    result = think(h, w)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h, w):
    if h == 1 or w == 1:
        return 1
    if w % 2 == 0:
        return w // 2 * h
    else:
        if h % 2 == 0:
            return w * (h // 2)
        else:
            return w * (h // 2) + (w // 2) + 1


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 52076
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

char s[1011];

int main()
{
    int i,j,k;
    char la=' ';
    int ans=0;
    cin>>s;
    int n=strlen(s);
    for(i=0;i<n;i++)
    {
        if(ans==0 && s[i]=='C')
        {
            ans++;
        }
        else if(ans==1 && s[i]=='F')
        {
           ans++;
        }
    }
    
    if(ans==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
} 



Measured memory_bytes: 256
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        if(a == b){
            System.out.println("EQUAL");
        }
        else if(a > b){
            System.out.println("GREATER");
        }
        else if(a < b){
            System.out.println("LESS");
        }
    }
}


Measured memory_bytes: 23124
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        int ans=0;
        boolean skip=false;
        for(int i=0;i<n;i++){
            int k=fsc.nextInt()-1;
            if(skip){
                skip=false;
                continue;
            }
            if(i==k){
                ans++;
                skip=true;
            }
        }
        fsc.close();
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K;
  cin >> N >> M >> K;
  bool res = false;
  for (int i = 0; i <= N; i++){
    for (int j = 0; j <= M; j++){
      if (i * j + (N - i) * (M - j) == K) res = true;
    }
  }
  cout << (res ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n;
  cin>>n;
  ll ans=0;
  vector<ll>a(n);
  for(int i=0;i<n;i++){
  	cin>>a[i];
    while(a[i]%2==0){
    	ans++;
      	a[i]=a[i]/2;
    }
    
  }
  
  
  
  cout<<ans<<endl;
 return 0; 
}

Measured memory_bytes: 384
#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, Y,z;
    bool lie = true;
    cin >> N >> Y;
    rep(x,N+1){
        rep(y,N+1){
            z = N - x - y;
            if(x*10000+y*5000+z*1000==Y&&z>=0){
                cout << x << " " << y << " " << z << endl;
                lie = false;
                x = N + 1;
                y = N + 1;
            }
        }
    }
    if(lie){
        cout << "-1 -1 -1" << endl;
    }
}

Measured memory_bytes: 256
INF = 1001001001
N, M, X = map(int, input().split())
C, A = [], []
for i in range(N):
    _c = list(map(int, (input().split())))
    _a = _c[1:]
    _c = _c[0]
    A.append(_a)
    C.append(_c)
ans = INF
for b in range(1<<N):
    money = 0
    point = [0]*M
    for i in range(N):
        if (b>>i)&1:
            money += C[i]
            for j in range(M):
                point[j] += A[i][j]
    for j in range(M):
        if point[j] < X:
            break
    else:
        ans = min(ans, money)
if ans == INF:
    print(-1)
else:
    print(ans)


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

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

void solve() {
  int x;
  cin >> x;
  cout << 1 - x << endl;
}

signed main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

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

using namespace std;

typedef long long ll;

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

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

// {unit, deadline}
vector<pair<ll, ll>> tasks;

int main(void) {
    ll N;
    cin >> N;

    tasks.resize(N);
    for (int i = 0; i < N; i++) {
        ll A, B;
        cin >> A >> B;
        tasks[i] = {A, B};
    }
    sort(tasks.begin(), tasks.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
            if (a.second == b.second) {
                return a.first < b.first;
            } else {
                return a.second < b.second;
            }
            });

    // for (auto &p : tasks) {
    //     cout << p.first << "," << p.second << endl;
    // }

    ll acc = 0;
    bool can_finish = true;
    for (int i = 0; i < N; i++) {
        acc += tasks[i].first;
        if (acc > tasks[i].second) {
            can_finish = false;
            break;
        }
    }

    if (can_finish) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

typedef long long ll;
int main(){
  ll x;
  cin>>x;
  int i;
  for(i=1;i<=x;i++){
    ll k;
    if(i%2){
      k = i*((i+1)/2);
    }else{
      k = i/2*(i+1);
    }
    if(k>=x) break;
  }
  cout<<i<<"\n";
}


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

void solve() 
{
    int k,a,b;cin>>k>>a>>b;
    for(int i=k;i<=1000;i+=k){
        if(i>=a&&i<=b){
            cout<<"OK"<<endl;
            return;
        }
    }
    cout<<"NG"<<endl;
}

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

Measured memory_bytes: 3652
#include <stdio.h>

int main() {
  int n, p, i, j, k, flag;
  int cnd[50];

  while(1) {
    flag = 0;
    for(i = 0; i < 50; i++) {
      cnd[i] = 0;
    }
    scanf("%d %d", &n, &p);
    if(n == 0 && p == 0){
      break;
    }
    else if(n < 3 || n > 50 || p < 2 || p > 50) {
      scanf("%d %d", &n, &p);
    }
    j = p;
    while(1) {
      for(i = 0; i < n; i++) {
        if(j > 0) {
          cnd[i] += 1;
          j--;
          if(cnd[i] == p) {
            printf("%d\n", i);
            flag = 1;
            break;
          }
        }
        else if(cnd[i] > 0) {
          j += cnd[i];
          cnd[i] = 0;
        }
      }
      if(flag == 1)
        break;
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl h(N);
  rep(i, N) cin >> h[i];

  stable_sort(h.begin(), h.end());

  ll ans = (ll)pow(10, 17);

  rep(i, N - K + 1)
    ans = min(ans, h[i + K - 1] - h[i]);

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 4316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char r[], a[];
		int hit, blow;

		while (true) {
			r = sc.next().toCharArray();
			a = sc.next().toCharArray();
			if (r.length == 1 && a.length == 1 && r[0] == '0' && a[0] == '0') {
				break;
			}
			hit = blow = 0;
			for (int i = 0; i < 4; i++) {
				if (r[i] == a[i]) {
					hit++;
				}
			}
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (i != j && a[i] == r[j]) {
						blow++;
					}
				}
			}
			System.out.println(hit + " " + blow);
		}
	}
}

Measured memory_bytes: 44156
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll A[100010], B[100010];
    rep(i,0,N) cin >> A[i] >> B[i];
    // vector<lpair> lp;
    // rep(i,0,N) lp.push_back(make_pair(A[i], B[i]));
    // sort(lp.begin(), lp.end());
    ll ans = 0;
    rrep(bit,31,0){
        if(!((K>>bit) & 1)) continue;
        ll k_tmp = K - (1LL<<bit);
        ll tt = 0;
        rep(i,0,N){
            bool ok = true;
            rrep(j,31,0){
                if(j > bit){
                    if(!((K>>j) & 1) && ((A[i]>>j) & 1)){
                        ok = false;
                    }
                }else if(j == bit){
                    if((A[i]>>j) & 1) ok = false;
                }
            }
            if(ok) tt += B[i];
        }
        ans = max(ans, tt);
    }
    ll tt = 0;
    rep(i,0,N){
        bool ok = true;
        rrep(j,31,0){
            if(!((K>>j) & 1) && ((A[i]>>j) & 1)){
                ok = false;

            }
        }
        if(ok) tt += B[i];
    }
    ans = max(ans, tt);
    print(ans);

}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;

int main() {
	random_device rd;
	mt19937 mt(rd());
	int N, M; cin >> N >> M;
	vector<string> a(N);
	rep(i, N) cin >> a[i];
	rep(t, 100000) {
		vector<vector<bool>> b(M, vector<bool>(M, true));
		rep(j1, M) for (int j2 = j1; j2 < M; j2++)
			rep(i, N) if (a[i][j1] != a[N - 1 - i][j2]) b[j1][j2] = false;
		vector<bool> dp(1<<M);
		dp[0] = true;
		rep(S, 1<<M) if (dp[S])
			rep(j1, M) for (int j2 = j1 + 1; j2 < M; j2++)
				if (!(S>>j1 & 1) && !(S>>j2 & 1) && b[j1][j2])
					dp[S | 1<<j1 | 1<<j2] = true;
		bool ok = false;
		if (M % 2 == 0) ok = dp.back();
		else {
			rep(j, M) if (dp[(1<<M) - 1 - (1<<j)] && b[j][j]) ok = true;
		}
		if (ok) {
			cout << "YES" << endl;
			return 0;
		}
		shuffle(a.begin(), a.end(), mt);
	}
	cout << "NO" << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    ll k;
    cin >> s >> k;
    int n = s.length();
    vector<int> S;
    int curr = 1;
    F(i, 1, n){
        if(s[i] != s[i - 1]){
            S.pb(curr);
            curr = 1;
        }
        else ++curr;
    }
    S.pb(curr);
    ll ans = 0;
    I(x, S){
        ans += k * (x/2);
    }
    if(k == 1 || s[0] != s.back()){
        cout << ans;
        ret 0;
    }
    if(S.size() == 1u){
        ans = k * n / 2;
        cout << ans;
        ret 0;
    }
    ans = 0;
    n = S.size();
    F(i, 0, n){
        if(i != 0 && i + 1 != n){
            ans += k * (S[i]/2);
        }
        else{
            ans += S[i]/2;
        }
    }
    ll kek = S[0] + S.back();
    ans += kek /2 * (k - 1);
    cout <<  ans;
    return 0;
}


Measured memory_bytes: 256
gets
h = gets.chomp.split(" ").map(&:to_i)
ans = true
prev_max = h[0]

h.each do |i|
    if i < prev_max - 1
        ans = false
        break
    end
    prev_max = i > prev_max ? i : prev_max
end

puts ans ? "Yes" : "No"

Measured memory_bytes: 9604
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    if((N+1)/2>=K)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


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

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

  int ans = 1;
  for(int i = sqrt(M); i >= 1; i--) {
    if(M % i == 0) {
      if(M / i >= N) ans = max(ans, i);
      if(i >= N) ans = max(ans, M/i);
    }
  }

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


Measured memory_bytes: 256
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define INF (100000)

DWORD N, L;

void solve_main()
{
	QWORD qwSum = 0;
	DWORD dwMinAbs = INF;
	DWORD dwDelNum = INF;
	DWORD dwAns = 0;
	cin >> N >> L;

	REP(i, 1, N + 1) {
		DWORD dwIPoint = L + i - 1;
		DWORD dwPreMin = dwMinAbs;

		dwIPoint = abs(dwIPoint);
		dwMinAbs = min(dwMinAbs, dwIPoint);
		if (dwPreMin != dwMinAbs) {
			dwDelNum = i;
		}
	}

	REP(i, 1, N + 1) {
		if (i != dwDelNum) {
			dwAns += i;
		}
	}
	cout << (L - 1) * (N - 1) + dwAns << endl;
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int W, A, B;
  cin >> W >> A >> B;
  int X;
  if(A <= B) {
    X = B - A - W;
  }
  else {
    X = A - B - W;
  }
  if(X < 0) {
    X = 0;
  }
  cout << X << endl;
}


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long X = scan.nextLong();
        long Y = scan.nextLong();
        long Z = Y / X;
        long answer = f(Z)+1;
        System.out.println(answer);
    }
    public long f(long Z) {
        long t = 1;
        long result = 0;
        while (t < Z) {
            t *= 2;
            result += 1;
        }
        if (t == Z) {
            return result;
        }
        return result - 1;
    }
}


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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

void solve()
{
    ll i,j,l,r,n,k,m,u,v,x,y,z,q,p,h;
    cin>>n;
    ll ans=0;
    vector<ll> vc(n);
    for(i=0;i<n;i++) cin>>vc[i];
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            for(k=j+1;k<n;k++){
                ll mx=max({vc[i],vc[j],vc[k]});
                if( vc[i]!=vc[j] && vc[i]!=vc[k] && vc[j]!=vc[k] && vc[i]+vc[j]+vc[k]-mx>mx){
                        ans++;
                }
            }
        }
    }
    cout<<ans<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<<i++<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 3656
import copy
n = int(input())
a = [int(input()) for _  in range(n)]
jisyo = {}
flag = False
if(a.count(max(a))!=1):
	flag = True
b = copy.deepcopy(a)
b.sort()
for i in a:
	if flag:
		print(b[-1])
	elif(i == b[-1]):
		print(b[-2])
	else:
		print(b[-1])

Measured memory_bytes: 97368
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();

        int[] A = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            max = Math.max(max, A[i] = in.i());
        }
        int[] cnt = new int[max + 2];
        cnt[0] = 3;

        long ans = 1;
        for (int i = 0; i < N; i++) {
            int s = cnt[A[i]] - cnt[A[i] + 1]++;
            if (cnt[A[i] + 1] > 3 || s <= 0) {
                ans = 0;
                break;
            }
            ans = ans * s % 1_000_000_007;
        }

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 36596
#include<iostream>
#include<algorithm>
using namespace std;
int p[3][100007];
long long int dp[100007];
int main(){
	int n;
	int i,j,k;
	long long int s=0;
	cin>>n;
	for(i=0;i<3;i++){
		for(j=0;j<n;j++){
			cin>>p[i][j];
		}
		sort(p[i],p[i]+n);
	}
	
	for(i=0,j=0;i<n;i++){
		while(j<n && p[1][i]>=p[2][j]){j++;}
		dp[i]=n-j;
	}
	for(i=n-1;i>=0;i--){
		dp[i]+=dp[i+1];
	}
	for(i=0,j=0;i<n;i++){
		while(j<n && p[0][i]>=p[1][j]){j++;}
		s+=dp[j];
	}
	cout<<s<<endl;
	return 0;
}
	
	
	


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    ll n,r;
    cin>>n>>r;
    if(n>=10)
        cout<<r<<endl;
    else
        cout<<r+(100)*(10-n)<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>
#include <utility>
#include <tuple>
#include <map>    
#include <queue> 
#include <set>  
#include <stack> 
#include <deque>  
#include <unordered_map> 
#include <unordered_set> 
#include <bitset>

using namespace std;

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

	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	double s1 = 0.0;
	for (int i = 0; i < N; i++) {
		s1 += 1.0 / A.at(i);
	}

	double s2 = 1.0 / s1;
	cout << s2 << endl;
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k, i, j;
    cin >> h >> w >> k;
    int x0,y0,x1,y1;
    cin >> x0 >> y0 >> x1 >> y1;
    x0--;y0--;x1--;y1--;
    char grid[h][w];
    for(i=0;i<h;i++){
        string s;
        cin >> s;
        for(j=0;j<w;j++){
            grid[i][j] = s[j];
        }
    }
    vvi dist(h, vi(w, inf));
    vvi used(h, vi(w));
    dist[x0][y0] = 0;
    used[x0][y0] = 1;
    queue<pii> Q;
    Q.push({x0,y0});
    int x,y;
    bool found = false;
    while(!Q.empty() && (!found)){
        tie(x,y) = Q.front();
        Q.pop();
        used[x][y] = 2;
        if(x == x1 && y == y1) break;
        for(int dd = 0;dd < 4;dd++){
            i = x + dx[dd];
            j = y + dy[dd];
            while(  (i >= 0 && i < h) 
                    && (j >= 0 && j < w) 
                    && grid[i][j] != '@'){
                if(used[i][j] == 2) break;
                if(abs(i - x) > k || abs(j - y) > k) break;
                if(!used[i][j]){
                    dist[i][j] = dist[x][y] + 1;
                    used[i][j] = 1;
                    Q.push({i,j});
                    if(i == x1 && j == y1) found = true;
                }
                i += dx[dd];
                j += dy[dd];
            }
        }
    }
    
    if(dist[x1][y1] == inf){
        cout << "-1\n";
    }else{
        cout << dist[x1][y1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 15968
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;

ll power(ll x, ll n) {
    x = x % mod;
    ll res = 1;
    while (n) {
        if (n & 1)
            res = (res * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return res;
}

ll inv(ll x) {
    return power(x, mod - 2);
}


void solve() {
    int n;
    cin >> n;
    int N = 1000000+1;
    vector<ll> a(N, 0);
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        ++a[x];
    }
    vector<ll> s1(N, 0), s2(N, 0);
    for (ll i = 1; i < N; ++i) {
        for (ll j = i; j < N; j += i) {
            s1[i] = (s1[i] + j * a[j]) % mod;
            s2[i] = (s2[i] + j * j * a[j]) % mod;
        }
    }
    ll res = 0;
    vector<ll> ans(N);
    for (ll d = N - 1; d > 0; --d) {
        ans[d] = ((((s1[d] * s1[d]) % mod) - s2[d] + mod) * inv(2 * d)) % mod;
        for (ll j = 2 * d; j < N; j += d) {
            ans[d] = (((ans[d] - ans[j] * (j / d)) % mod) + mod) % mod;
        }
        res = (res + ans[d]) % mod;
    }
    cout << res << endl;


}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
   
        solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int i,j=0,k;
  int N;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  
  qsort(A,N,sizeof(int),compare_int);
  
  for(i=0;i<N;i++){
    k=1;
    while(A[i] == A[i+1]){
      i++;
      k++;
    }
    if(k%2 == 1)
      j++;
  }
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <cmath>
typedef long long LL;
using namespace std;
 int main(){
    int n;
    int tmp;
    int min;
    int sum = 0;
    int leftsum = 0;
    vector<int> w;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp;
        w.push_back(tmp);
        sum += tmp;
    }
    min = sum;
    for(int i=0; i<n; i++){
        leftsum += w[i];
        if(abs(sum-2*leftsum)<min){
            min = abs(sum-2*leftsum);
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const int N = 2e5+10;

int fac[N], ifac[N], inv[N];
void pre() {
  fac[0] = ifac[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (MOD - (ll) (MOD/i) * inv[MOD%i] % MOD) % MOD; }
  for (int i = 1; i < N; i++) {
    fac[i] = (ll) fac[i-1] * i % MOD;
    ifac[i] = (ll) ifac[i-1] * inv[i] % MOD;
  }
}

ll choose(ll n, ll k) {
  if (k < 0 || k > n) return 0;
  return (ll) fac[n] * ifac[k] % MOD * ifac[n-k] % MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pre();
  int b, w; cin >> b >> w;
  ll iv = inv[2];
  ll now = 0, nob = 0, ow = 1;
  for (int i = 1; i < b+w; i++) {
    cout << (now + inv[2] * ow) % MOD << nl;
    now = (now + choose(i-1, w-1) * iv) % MOD;
    nob = (nob + choose(i-1, b-1) * iv) % MOD;
    ow = (1 - now - nob + 2*MOD) % MOD;
    iv = iv * inv[2] % MOD;
  }
  cout << (now + inv[2] * ow) % MOD << nl;
  return 0;
}


Measured memory_bytes: 4608
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
prev = -1
for i in A:
    ans += B[i-1]
    if prev == i - 1:
        ans += C[prev-1]
    prev = i
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

const int maxn = 1005;

struct P {
    long long x, y, r;
};

ll sq(ll a) {
    return a*a;
}

ll distsq(P p, P q) {
    return sq(p.x-q.x) + sq(p.y-q.y);
}

int n, p[maxn], groups, group[maxn];
P s, t, c[maxn];
std::vector<P> g[maxn];
double dist[maxn][maxn];
bool seen[maxn];

int find(int i) {
    if (i == p[i]) return i;
    else return p[i] = find(p[i]);
}

void join(int i, int j) {
    p[find(i)] = find(j);
}

int main() {
    scanf("%lld%lld%lld%lld", &s.x, &s.y, &t.x, &t.y);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < n; i++) scanf("%lld%lld%lld", &c[i].x, &c[i].y, &c[i].r);
    for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) {
        if (distsq(c[i], c[j]) <= c[i].r + c[j].r) join(i, j);
    }
    for (int i = 0; i < n; i++) if (find(i) == i) group[i] = groups++;
    for (int i = 0; i < n; i++) {
        group[i] = group[find(i)];
        g[group[i]].pb(c[i]);
    }
    g[groups++].pb(s);
    g[groups++].pb(t);
    for (int i = 0; i < groups; i++) for (int j = 0; j < groups; j++) {
        dist[i][j] = 1e20;
        for (auto &p : g[i]) for (auto &q : g[j]) {
            domin(dist[i][j], std::sqrt(distsq(p, q)) - p.r - q.r);
        }
        domax(dist[i][j], 0.);
    }

    std::priority_queue<std::pair<double, int>> q;
    q.emplace(0, groups-2);
    while (!q.empty()) {
        double d; int i; std::tie(d, i) = q.top();
        q.pop();

        if (seen[i]) continue;
        else seen[i] = true;
        if (i == groups-1) {
            printf("%.10lf\n", -d);
            break;
        }

        for (int j = 0; j < groups; j++) if (!seen[j]) {
            q.emplace(d - dist[i][j], j);
        }
    }
}


Measured memory_bytes: 16496
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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 (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    vector<Int> a(n);
    vector<Int> rui(n+1);
    rui[0] = 0;
    rep(i,n){
        cin >> a[i];
        rui[i+1]=rui[i]+a[i];
    }
    /*for(auto &i:rui){
        cout << i << " ";
    }
    cout << endl;*/
    Int  ans = INF;
    //debug(rui[n]);
    for(int i=1;i<n;i++){
        if(n-i<1) continue;
        chmin(ans,abs((rui[n]-rui[i])-rui[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
import sys

n, m, c = map(int, sys.stdin.readline().split())
blist = list([int(i) for i in sys.stdin.readline().split()])

ans = 0
for _ in range(n):
    tmp = list([int(i) for i in sys.stdin.readline().split()])
    check = c
    for i in range(m):
        check += tmp[i] * blist[i]
    if check > 0:
        ans += 1

print(ans)


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

string table[10] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

string convert(string s) {
    if (s == "") return "";
    int i = s[0] - '0';
    int j = s.size() - 1;
    return string(1, table[i][j % (int)table[i].size()]);
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        string ans = "", t = "";
        for (int i=0; i<(int)s.size(); ++i) {
            if (s[i] == '0') {
                ans += convert(t);
                t = "";
            } else {
                t += s[i];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3136
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 1<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){ 
	int n; cin >> n;
	vector<int> a(n+1);
	rep(i, n) cin >> a[i+1];

	int ans = 0;
	bool flag = false;
	vector<int> b(n+1);
	for(int i=n; i>0; i--){
		int count = 0;
		for(int j=i; j<=n; j+=i){
			if(b[j] == 1) count++;
		}
		if(a[i] == 1){
			if(count % 2 == 0){
				b[i] = 1;
				ans++;
			}
		} else{
			if(count % 2 == 1){
				b[i] = 1;
				ans++;
			}
		}
	}

	if(flag) cout << -1 << endl;
	else{
		cout << ans << endl;
		rep2(i, 1, n+1){
			if(b[i] == 1) cout << i << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
#define FOR(i, a, b) for(int i=a; i<b; i++)
int dp[1000001] = {0};

bool comp(const pair<int, int> &a, const pair<int, int> &b){
	return a.first>b.first;
}
bitset<1000010> bs;
int sieveSize = 1000001;
vector<int> primes;
void init(){
	bs.set();
	bs[0]=bs[1]=0;
	for(int i=2;i<=sieveSize;i++){
		if(bs[i]){
			primes.pb(i);
			for(int j=i*i;j<=sieveSize;j+=i){
				bs[j]=0;
			}
		}
	}
}

void solve(){ 	
	int a, b, cnt=0;
	vector<int> res;
	init();
	cin>>a>>b;
	int n = __gcd(a, b);
	for(int x :primes){
		if(n%x==0)cnt++;
		while(n%x==0){
			n/=x;
		}
	}
	if(n>1) cnt++;
	cout<<cnt+1;
}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 1528
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d = input.nextInt();
        while (true) {
            c -= b;
            if (c <= 0) {
                System.out.println("Yes");
                break;
            }
            a -= d;
            if (a <= 0) {
                System.out.println("No");
                break;
            }
        }
    }
}

Measured memory_bytes: 35608
#include <stdio.h>

int	main(void)
{
  	long long int	a;
  	long long int	b;
  	int	num;
  	long long int	x;
  	long long int	r;
  	long long int   l;
  	long long int   tmp;
  
  	num = scanf("%lld %lld", &a, &b);
  	if (num != 2)
    	return (0);
  
	x = a * b;
 
	if (a < b)
    {
	    tmp = a;
    	a = b;
    	b = tmp;
	}
 
	r = a % b;
  	while(r!=0){
    	a = b;
    	b = r;
    	r = a % b;
  	}
  
	l = x / b;
  	printf("%lld", l);
 	return (0);
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);
  int k; cin >> k;
  vll a(k);
  REP(i, k) cin >> a[i];

  ll l = 2, r = 2;
  RREP(i, k-1) {
    l = l + (a[i] - ((l-1) % a[i] + 1));
    r = r - (r % a[i]);
    r = r + a[i] - 1;
    //cout << l << ":" << r << endl;
    if(r < l) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << l << " " << r << endl;
}


Measured memory_bytes: 1024