akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <double, double> P;
typedef pair<P,char> PP;
const ll MOD=1000000007;
int n;
vector<PP> point;
vector<P> x,y;
void operation(vector<P> X, vector<P> &Y){
    rep(i,0,n){
        if(X[i].sc==-1){
            Y.pb(P(X[i].fr, X[i].sc));
            break;
        }
    }
    rep(i,0,n){
        if(X[i].sc==0){
            Y.pb(P(X[i].fr, X[i].sc));
            break;
        }
    }
    rep(i,0,n){
        if(X[i].sc==1){
            Y.pb(P(X[i].fr, X[i].sc));
            break;
        }
    }
}
vector<double> res;
void prepre(P X, P Y){
    if(X.sc==-1&&Y.sc==0) res.pb(X.fr-Y.fr);
    if(X.sc==-1&&Y.sc==1) res.pb((X.fr-Y.fr)/2);
    if(X.sc==0&&Y.sc==1) res.pb(X.fr-Y.fr);
}
void pre(vector<P> X){
    if(sz(X)>=2)prepre(X[0], X[1]);
    if(sz(X)==3){
        prepre(X[0], X[2]); prepre(X[1],X[2]);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    point.resize(n);
    rep(i,0,n){
        cin>>point[i].fr.fr>>point[i].fr.sc>>point[i].sc;
    }
    x.resize(n);
    y.resize(n);
    if(n==1){
        cout <<0<<"\n";
        return 0;
    }
    rep(i,0,n){
        x[i].fr=point[i].fr.fr;
        if(point[i].sc=='R') x[i].sc=1;
        else if(point[i].sc=='L') x[i].sc=-1;
        else x[i].sc=0;
        y[i].fr=point[i].fr.sc;
        if(point[i].sc=='U') y[i].sc=1;
        else if(point[i].sc=='D') y[i].sc=-1;
        else y[i].sc=0;
    }
    sor(x); sor(y);
    vector<P> minx, maxx, miny, maxy;
    operation(x,minx);
    operation(y,miny);
    rev(x); rev(y);
    operation(x,maxx);
    operation(y,maxy);
    pre(minx); pre(miny); pre(maxx); pre(maxy);
    double ans=1e18;
    res.pb(0);
    for(auto &e: res){
        if(e<0) continue;
        double MAXX=-1e18, MAXY=-1e18, MINX=1e18, MINY=1e18;
        for(auto &f: maxx){
            MAXX=max(MAXX, f.fr+f.sc*e);
        }
        for(auto &f: maxy){
            MAXY=max(MAXY, f.fr+f.sc*e);
        }
        for(auto &f: minx){
            MINX=min(MINX, f.fr+f.sc*e);
        }
        for(auto &f: miny){
            MINY=min(MINY, f.fr+f.sc*e);
        }
        if(MAXX-MINX<=ans&&MAXY-MINY<=ans){
            ans=min(ans, (MAXX-MINX)*(MAXY-MINY));
        }
    }
    cout <<setprecision(15)<<ans<<"\n";
}

Measured memory_bytes: 7296
n,t = map(int,input().split())
dpa = [[0 for i in range(t)] for j in range(n+1)]
dpb = [[0 for i in range(t)] for j in range(n+1)]

for i in range(t):
   dpa[0][i] = 0
   dpb[0][i] = 0
abl = []
for _ in range(n):
   a,b = map(int,input().split())
   abl.append((a,b))

for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpa[i+1][j] = max(dpa[i][j], dpa[i][j-abl[i][0]] + abl[i][1])
      else:
         dpa[i + 1][j] = max(dpa[i][j], dpa[i + 1][j])

abl = abl[::-1]
for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpb[i+1][j] = max(dpb[i][j], dpb[i][j-abl[i][0]] + abl[i][1])
      else:
         dpb[i + 1][j] = max(dpb[i][j], dpb[i + 1][j])

abl = abl[::-1]
ans = 0
for i in range(t):
   for j in range(n):
      ans = max(ans, dpa[j][i]+dpb[n-j-1][t-i-1]+abl[j][1])

print(ans)

Measured memory_bytes: 194440
from sys import stdin, stdout
from collections import Counter,deque
import math
cin = stdin.readline
cout = stdout.write
def inpn():
    return(int(cin()))
def inpl():
    return(list(map(int,cin().split())))
def inps():
    return cin()[:-1]
def inpv():
    return (map(int, cin().split()))
def outs(s):
    cout(s)
def outn(n):
    cout(str(n))
def outl(l):
    for i in l:
        cout(str(i)+" ")
def outb(s):
    cout(str(s))


# n = inpn()
# l=inpl()
# m=1000000007
# add=0
# for i in range(n-1):
#     for j in range(i+1,n):
#         add+=(l[i]%m*l[j]%m)%m
#
# outn(add%m)
# cout("\n")

s=inps()
t=inps()
ans=1000
if t in s:
    outn(0)
    cout("\n")
else:
    if len(s)!=len(t):
        for i in range(len(s)-len(t)):
            count=0
            for j in range(len(t)):
                if s[i+j]!=t[j]:
                    count+=1
            ans=min(ans, count)
        outn(ans)
        cout("\n")
    else:
        ans=0
        for i in range(len(s)):
            if s[i]!=t[i]:
                ans+=1
        outn(ans)
        cout("\n")

















Measured memory_bytes: 68260
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int A,B;
  cin>>A>>B;
  cout<<(B-1+A-1-1)/(A-1)<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
  if a[i]+1==a[i+1]:
    ans=ans+c[a[i]-1]
print(ans)

Measured memory_bytes: 9112
from collections import deque
import sys
s = deque(list(input()))
Q = int(input())
cnt = 0

for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    cnt = (cnt+1) % 2
  elif q[1] == '1':
    if cnt == 0:
      s.appendleft(q[2])
    else:
      s.append(q[2])
  else:
    if cnt == 0:
      s.append(q[2])
    else:
      s.appendleft(q[2])

if cnt == 1:
  s.reverse()
print("".join(s))

Measured memory_bytes: 8804
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }

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


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n, k;
    cin >> k >> n;
    set<int> v;
    rep(i, 0, n) {
        int x;
        cin >> x;
        v.insert(x);
    }
    int cur_dist = 0;
    while(1)
    {
        if(v.find(k - cur_dist) == v.end()) {
            cout << k - cur_dist << '\n';
            return 0;
        }
        else if(v.find(k + cur_dist) == v.end()) {
            cout << k + cur_dist << '\n';
            return 0;
        }
        cur_dist++;
    }
    return 0;
}



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

int main() {
  int n,h;
  cin >> n >> h;
  int count=0;
  for(int i=0;i<n;i++) {
    int temp;
    cin >> temp;
    if(temp>=h) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INt_MAX
#define inf llONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 10;

pair < ll, ll > a[N], tmp;
ll c[N];
ll dp[100];

bool cmp(pair < ll, ll > A, pair < ll, ll > B) {
    return A.fir * (B.sec + 1) > B.fir * (A.sec + 1);
}

void solve() {

    int n; ll t;
    scanf("%d %lld", &n, &t);
    int cnt1 = 0, cnt2 = 0;
    for(ll i = 1 , x , y ; i <= n ;i ++)
     {
       scanf("%lld%lld" , &x , &y) ;
       if(x == 0) c[++ cnt2] = y + 1;
       else a[++ cnt1] = {x , y} ;
     }
    sort(c + 1 , c + cnt2 + 1) ;
    sort(a + 1 , a + cnt1 + 1 , cmp) ;
    for(int i = 1; i <= 30 ;i ++) dp[i] = t + 1 ;
    dp[0] = 0 ;
    int cnt = 0 ;
    for(int i = 1; i <= cnt2 ;i ++) c[i] += c[i - 1] ;

    for(int i = 1; i <= cnt1 ;i ++)
    {
      for(int j = 30 ;j >= 1 ;j --)
       dp[j] = min(dp[j] , (dp[j - 1] + 1) * (a[i].first + 1)+ a[i].second) ;
    }
    int ans = 0 ;
    for(int i = 0 ;i <= 30 ;i ++)
     {
       if(dp[i] > t) continue ;
       int j = 0 ;
       if(cnt2)
        j = upper_bound(c + 1 , c + cnt2 + 1 , t - dp[i]) - c - 1;
       ans = max(ans , i + j) ;
     }
    printf("%d\n", ans);
    return ;
}
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3584
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
     string s;
     cin >> s;
     ll f= 0 ;
     for(auto it : s) {

         f += (it- '0');
         f %= 9;
     }

     if(f)
        cout << "No";
    else
        cout << "Yes";
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);   
    //TEST
     solve();
}



Measured memory_bytes: 3716
#include <iostream>

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

   long long L[N+1];
   L[0] = 2;
   L[1] = 1;
   for(int i=2; i<=N; ++i){
      L[i] = L[i-1] + L[i-2];
   }
   std::cout << L[N] << std::endl;
   return 0;
}


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

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int,int> pii;


int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<1ll*(a+b-1)/b*c<<endl;
}

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

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

int main() {
  int a, b,  c;
  cin >> a >> b >> c;
  int count = 3;
  if(a == b) --count;
  if(a == c) --count;
  if(b == c) --count;
  if(a == b  && a == c) count = 1;
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N,m,i,j,x;
    scanf("%d\n",&N);
    m=N-1;
    int a[m];
    scanf("%d",&a[0]);
    for(N=1;N<=m;N++){
        scanf(" %d",&a[N]);
    }
    for(i=0;i<=m;i++){
        j=i+1;
        printf("%d",a[0]);
        for(N=1;N<=m;N++){
            printf(" %d",a[N]);
        }
        printf("\n");
        while(j>=1 && a[j-1]>a[j]){
            x=a[j-1];
            a[j-1]=a[j];
            a[j]=x;
            j--;
        }
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  vector<int> WW(N,0);
  int tot = 0;
  cin >> W[0];
  WW[0] = W[0];
  tot += W[0];
  for (int i=1; i<N; i++) {
    cin >> W[i];
    WW[i] = WW[i-1] + W[i];
    tot += W[i];
  }
  int ans = 10101010;
  int term = 0;
  
  for (int i=0; i<N; i++) {
    term = abs(tot - WW[i] * 2);
    ans = min(term,ans);
  }
  
  cout << ans << endl;
  return 0;
  
}

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

const int INF = 1 << 20;
int N, Ma, Mb;
int a[40], b[40], c[40];
int dp[410][410];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> Ma >> Mb;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  fill_n((int*)dp, 410 * 410, INF);
  dp[0][0] = 0;
  for (int $ = 0; $ < N; $++) {
    for (int i = 400; i - a[$] >= 0; i--) {
      for (int j = 400; j - b[$] >= 0; j--) {
        if (dp[i - a[$]][j - b[$]] == INF) continue;
        dp[i][j] = min(dp[i][j], dp[i - a[$]][j - b[$]] + c[$]);
      }
    }
  }
  int ans = INF;
  for (int i = 1; Ma * i < 410 && Mb * i < 410 ; i++) {
    ans = min(ans, dp[Ma * i][Mb * i]);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = list(map(int, input().split()))

ans = 0
if n > 1:
    ans += (n * (n-1))//2
if m > 1:
    ans += (m * (m-1))//2

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

string S, T;
int dp[3010][3010];

int main () {

    cin >> S >> T;
    int n = (int)S.size();
    int m = (int)T.size();

    // LCSの長さを求める
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (S[i] == T[j]) {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            }
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    // dpテーブルからLCSを復元
    string ans = "";
    int left_chars = dp[n][m]; // あと何文字残っているか
    for (int i = n; i > 0; i--) {
        for (int j = m; j > 0; j--) {
            if (dp[i-1][j] == dp[i][j-1] && dp[i][j-1] == dp[i-1][j-1] && dp[i-1][j-1] != dp[i][j] && dp[i][j] == left_chars) {
                ans = (char)S[i-1] + ans;
                left_chars--;
                break; // 同じ箇所の文字は1回だけ使用可能
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

#include <bits/stdc++.h>
using namespace std;

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;

        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
	string s,s1,str;
	map<ll,ll>MAP;
	vector<ll>v;
	cin>>n;
	ll arr[n];

	cin>>x;
	FOR(i,n-1)
	{
	    a=0;
	    cin>>y;
	    if(x>y)
            a=x-y;
        sum=sum+a;
        x=y+a;

	}
	cout<<sum;

}


Measured memory_bytes: 3668
import java.util.Scanner;
public class Main {

	static int answer = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		if ((N<1) || (N>100)) {
			System.out.print("1から100の間で入力してください。");

		} else {
			int i = sc.nextInt();
			if ((i<1) || (i>N)) {
			System.out.print("1から"+N+"の間で入力してください。");

			} else {
				answer = N - i + 1;
			}
		}

		if (!(answer == 0)) {
			System.out.print(answer);
		}

        sc.close();

	}

}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

int main(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

Measured memory_bytes: 3544
import math

x = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


while True:
    if is_prime(x):
        print(x)
        exit()
    else:
        if x % 2 ==0:
            x += 1
        else:
            x += 2




Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,A,B,C=MAP()
L=[INT() for i in range(N)]
ABC=[A,B,C]

ABCs=[[] for i in range(3)]
for i, x in enumerate(ABC):
    # どの材料を使って作るとMPがいくらかかるかを全組み合わせ試す
    for j in range(1<<N):
        if j==0:
            ABCs[i].append((INF, j))
            continue
        sm=cnt=0
        for k in range(N):
            if j>>k&1:
                sm+=L[k]
                cnt+=1
        mp=(cnt-1)*10
        mp+=abs(x-sm)
        ABCs[i].append((mp, j))
    ABCs[i].sort()

mn=INF
# 3つだけなので、どれ優先するか順番全部試す
for perm in permutations([0,1,2]):
    msk=sm=0
    for i in perm:
        for j in range(len(ABCs[i])):
            mp,k=ABCs[i][j]
            # ビットに重複がなければ、その組み合わせは使える
            if msk|k==msk^k:
                sm+=mp
                msk+=k
                break
    mn=min(mn, sm)
print(mn)


Measured memory_bytes: 5552
#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; cin>>N;
    string s; cin>>s;

    vint sum(N+1);
    REP(i,N) sum[i+1]=sum[i]+(s[i]=='E');

    int ans=N;
    REP(i,N){
        int l=i-sum[i];
        int r=sum[N]-sum[i+1];
        ans=min(ans,l+r);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            
            while(true)
            {
                int result = 0;
                string[] input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[2]);
                string op = input[1];

                if(op == "+") result = a + b;
                else if(op == "-") result = a - b;
                else if(op == "*") result = a * b;
                else if(op == "/") result = a / b;
                else Environment.Exit(0);

                Console.WriteLine(result);
            }
        }
    }
}



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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int m[maxn];

int main()
{
    int k, n;
    cin >> k >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    int h = 0;
    for(int i = 0; i < n - 1; i++)
    {
        h = max(h, m[i+1] - m[i]);
    }
    h = max(h, k - m[n-1] + m[0]);
    cout << k - h << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

VI solve(int K, int N) {
  if(K % 2 == 0) {
    VI ans(N, K);
    ans[0] = K / 2;
    return ans;
  }
  VI ans(N, (K+1)/2);
  REP(i,0,N/2) {
    int &x = ans.back();
    if(x == 1) {
      ans.pop_back();
    } else {
      x--;
      while((int)ans.size() < N) {
        ans.push_back(K);
      }
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  int K, N;
  cin >> K >> N;
  VI ans = solve(K, N);
  FOR(a,ans) {
    cout << a << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    ll ans = 0;
    rep(i, n) {
        reps(j, i + 1, n) {
            reps(k, j + 1, n) {
                vector<ll> v(3);
                v[0] = l[i]; v[1] = l[j]; v[2] = l[k];
                sort(all(v));
                if ((v[0] == v[1]) || (v[1] == v[2])) continue;
                if ((v[0] + v[1]) <= v[2]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector <int> s(n-1);
    for (int i=0;i<n-1;i+=1){
        cin >> s[i];
    }
    vector <int> p(n,0);
    for(int i:s){
        p[i-1]+=1;
    }
    for(int i=0;i<n;i++){
        cout << p[i] << endl;
    }
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

int get_score(vector<int> t){
    vector<int> pos(26, 0);
    int ans = 0;
    rep(i, t.size()){
        int l = i + 1 - pos[t[i]];
        ans -= (l * (l-1) / 2) * c[t[i]];
        ans += s[i][t[i]];
        pos[t[i]] = i+1;
    }
    rep(i, 26){
        int l = t.size() + 1 - pos[i];
        ans -= (l * (l-1) / 2)* c[i];
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<int> t, pos(26, 0);
    rep(i, d){
        int max_score = -mod;
        int best_j = -1;
        rep(j, 26){
            t.push_back(j);
            int score = get_score(t);
            if(max_score < score){
                best_j = j;
                max_score = score;
            }
            t.pop_back();
        }
        t.push_back(best_j);
    }
    vector<int> ans = t;
    double start_temp = 1800, end_temp = 500;
    clock_t start_time = clock();
    int current_max_score = get_score(t);
    while(clock() < 1950000){
        int D = rand() % d, q = rand() % 26;
        int old = t[D];
        int olds = get_score(t);
        t[D] = q;
        int score = get_score(t);
        clock_t now_time = clock();
        double temp = start_temp + (end_temp - start_temp) * (now_time - start_time) / 19000;
        double prob = exp((score - olds)/temp);

        if(chmax(current_max_score, score)){
            ans = t;
        }else{
            if(prob <= (double)(rand() % 10000) / 10000){
                t[D] = old;
            }
        }

        if(prob >= ((rand()%inf)/(double)inf))t[D] = old;
    }
    rep(i, d)cout << ans[i]+1 << endl;
}


Measured memory_bytes: 3840
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


ll ans;
void dfs(ll h, ll cnt) {
  if (h<=0) return;

  ans += cnt;
  dfs(h/2, cnt*2);
}


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


  ll H; cin>>H;
  
  ans = 0;
  dfs(H, 1);
  
  cout << ans << endl;


  return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B ;
  int abottom;
  if(A%2==0){
    abottom = A*25/2;
  }else abottom = A*25/2+1;
  int atop;
  if(A%2==0){
    atop = (A+1)*25/2+1;
  }else atop = (A+1)*25/2;
  int bbottom=B*10;
  int btop = (B+1)*10;
  for(int i= abottom;i<atop;i++){
    for(int j=bbottom;j<btop;j++){
      if(i==j){
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int main(){
	int n, a[110], res = 0;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		if(i & 1 && a[i] & 1) ++ res;
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        for(int i = 0; i < k; i++){
            if(i%2 == 0){
                a = a/2;
                b += a;
            }else{
                b = b/2;
                a += b;
            }
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 22100
#include <iostream>

typedef long long ll;

ll gcd(ll a, ll b){ 
   if(a<b) return gcd(b,a);
   ll r;
   while(a%b){
      r = a%b;
      a = b;
      b = r;
   }   
   return b;
}

int main(){
   ll A, B;
   std::cin >> A >> B;

   std::cout << A*B/gcd(A,B) << std::endl;
   return 0;
}


Measured memory_bytes: 256
const main = arg => {
 const input = arg.trim().split("\n")[0].split(" ").map(num => parseInt(num, 10));
 const A = input[0];
 const B = input[1];
 const C = input[2];
 let result = "No";
 if(A < B && B < C){ result = "Yes"; }

 console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 19200
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();

    if n == k {
        put!(1);
        return
    }

    let mut idx = 0;
    for i in 0..n {
        let x: usize = sc.cin();
        if x == 1 {
            idx = i;
        }
    }

    let mut ans = n;
    for i in 0..k {
        let a = if idx > i { idx - i } else { 0 };
        let b = if idx+k < n+i { n+i-idx-k } else { 0 };
        ans = min(ans, 1 + (a+k-2)/(k-1) + (b+k-2)/(k-1));
    }
    put!(ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 10492
#include <algorithm>
#include <iostream>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <stack>
#include <map>
#define maxn 100000 + 5
#define INF 0x3f3f3f3f
#define xin(a) scanf("%d", &a)
#define ffr(i,m, n) for (i = m; i < n; i++)
#define clr(a, b) memset(a, b, sizeof(a));
#define pi acos(-1,0)
typedef double db;
typedef long long ll;
using namespace std;
void t(void)
{
    int t, n;
    xin(t);
    while (t--)
    {

    }
}
void n(void)
{
    int n, i;
    xin(n);
    cout<<(n>=30?"Yes":"No")<<endl;
}
int main(void)
{
    #ifndef ONLINE_JUDGE
    long _begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    n();
    #ifndef ONLINE_JUDGE
    long _end_time = clock();
    printf("time = %ld ms\n", _end_time - _begin_time);
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;

signed main(){
	int a,b,c;
	int ans;
	cin >> a >> b >> c;
	if(a == b){
		ans = c;
	}else if(b == c){
		ans = a;
	}else ans=b;
	cout << ans << endl;


    return 0;
}

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

//関数
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<long> V(N),C(N);
    for(int i=0;i<N;i++){
        cin>>V.at(i);
    }
    for(int i=0;i<N;i++){
        cin>>C.at(i);
    }
    //計算
    long ans=0;
    for(int i=0;i<N;i++){
        ans+= max((long)0,V.at(i)-C.at(i));
    }
    //出力
    cout<<ans<<endl;
}





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

int main(){
    int64_t t1, t2, a1, a2, b1, b2;
  
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1*t1+a2*t2==b1*t1+b2*t2) cout<<"infinity";
    else if(a1*t1>b1*t1&&a1*t1+a2*t2>b1*t1+b2*t2) cout<<0;
    else if(a1*t1<b1*t1&&a1*t1+a2*t2<b1*t1+b2*t2) cout<<0;
    else if(a1*t1<b1*t1&&a1*t1+a2*t2>b1*t1+b2*t2){
        int64_t sa=a1*t1+a2*t2-(b1*t1+b2*t2);
        int64_t sb=-a1*t1+b1*t1;
        int64_t as=1LL+sb/sa*2LL;
        
        if(sb%sa==0) as=as-1LL;
        cout<<as;

    }
    else if(a1*t1>b1*t1&&a1*t1+a2*t2<b1*t1+b2*t2){
        int64_t sa=-(a1*t1+a2*t2)+(b1*t1+b2*t2);
        int64_t sb=a1*t1-b1*t1;
        int64_t as=1LL+sb/sa*2LL;
        if(sb%sa==0) as=as-1LL;
        cout<<as;
        
    }
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  vector<int> a(n), b(n);
  for (int& x : a) {
    cin >> x;
  }
  for (int& x : b) {
    cin >> x;
  }
  int ans = inf;
  for (int i = 0; i < (1 << n); ++i) {
    vector<pair<int, int>> odd, even;
    for (int j = 0; j < n; ++j) {
      if ((i >> j) & 1) {
        if (j & 1) {
          odd.emplace_back(b[j], j);
        } else {
          even.emplace_back(b[j], j);
        }
      } else {
        if (j & 1) {
          even.emplace_back(a[j], j);
        } else {
          odd.emplace_back(a[j], j);
        }
      }
    }
    if (odd.size() == even.size() || odd.size() - 1 == even.size()) {
      sort(begin(odd), end(odd));
      sort(begin(even), end(even));
      int p = -1, p1 = 0, p2 = 0;
      bool ok = true;
      vector<int> d;
      for (int j = 0; j < n; ++j) {
        if (j & 1) {
          ok &= even[p2].first >= p;
          d.push_back(even[p2].second);
          p = even[p2++].first;
        } else {
          ok &= odd[p1].first >= p;
          d.push_back(odd[p1].second);
          p = odd[p1++].first;
        }
      }
      if (ok) {
        vector<int> c(n);
        iota(begin(c), end(c), 0);
        int cur = 0;
        for (int j = 0; j < n; ++j) {
          int p = find(begin(c), end(c), d[j]) - begin(c);
          while (p > j) {
            ++cur;
            swap(c[p], c[p - 1]);
            --p;
          }
        }
        ans = min(ans, cur);
      }
    }
  }
  if (ans == inf) {
    ans = -1;
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

int main(){
    int N;
    cin>>N;
    
    double a[N],b[N],Ans=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        b[i] = 1/a[i];
        Ans += b[i];
    }
    Ans = 1/Ans;
    cout<<Ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        long s = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            s += A[i];
        }
        
        for(int i=1; i<N-1; i=i+2){
            s -= 2 * A[i];
        }
        long[] B = new long[N];
        B[0] = s;
        System.out.print(B[0]);

        for(int i=1; i<N; i++){
            B[i] = 2 * A[i - 1] - B[i - 1];
            System.out.print(" " + B[i]);
        }
    }
}

Measured memory_bytes: 62540
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt(); //next(文字列), nextDouble, nextLine(1行)とか
    int K = sc.nextInt();
    boolean[] ans = new boolean[N];
    for (int i = 0; i < K; i++){
      int d = sc.nextInt();
      for (int j = 0; j < d; j++){
        int temp = sc.nextInt();
        ans[temp-1] = true;
      }
    }
    int ans2 = 0;
    for (int i = 0; i < N; i++){
      if(ans[i]){
        ans2++;
      }
    }
    System.out.println(N-ans2);        
  }
}


Measured memory_bytes: 46328
import math

A, B, C, D = map(int,input().split())
lcm = C*D//math.gcd(C,D)

c = B//C - (A-1)//C
d = B//D - (A-1)//D
cd = B//lcm - (A-1)//lcm

print(B-A+1 - c - d + cd)

Measured memory_bytes: 9180
#include<stdio.h>

int main(){
  int adata[100001],bdata[501],n,q,count=0,j,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&adata[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&bdata[i]);
    }
for(j=0;j<q;j++){
    for(i=0;i<n;i++){
      if(adata[i]==bdata[j]){
        count++;
        break;
      }
    }
  }

  printf("%d\n",count);
}



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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100000;
int n;
ll a[MAX_N];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  ll s = 0;
  forn(i,n) {
    cin >> a[i];
    s += a[i];
  }

  int r = 0;
  forn(i,n) {
    if (a[i] < 0) {
      a[i] *= -1;
      r = 1-r;
    }
  }
  if (r) {
    int i = min_element(a,a+n) - a;
    a[i] *= -1;
  }

  cout << max(s,accumulate(a,a+n,0LL)) << endl;


  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =2e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }

	  
	 void solve() {		 
	      int n,p;
	      cin>>n>>p;
	      string s;
	      cin>>s;
	        int ans=0;
	      if(p==2 || p==5) {
			
			     rep(i,0,n) {
					   if((s[i]-'0')%p==0 ) {
						     ans+=i+1;
						   } 
					 }
					 cout<<ans<<endl;
			  }
		 else {
			     mi mp;
			     mp[0]++;
			     mod=p;
			     int cur=0;
			     rep(i,0,n) {
				        	cur*=10;
				        	cur+=s[i]-'0';
				        	cur%=mod;
				        	int val=po(10,n-i+1)*cur%mod;
				        	mp[val]++;				   
					 }
					 
					 for(auto to:mp) {
						   ans+=(to.se*(to.se-1))/2;
						 }			 
						 cout<<ans<<endl;
			 }	  
			  
	      
	                
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    vector<ll> v(3);
    cin >> N >> v[0] >> v[1] >> v[2];
    vector<string> s(N);
    vector<int> i0(N), i1(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        i0[i] = s[i][0] - 'A';
        i1[i] = s[i][1] - 'A';
    }

    vector<char> ans(N);
    bool p = true;

    if (v[0] + v[1] + v[2] == 0)
        p = false;
    else {
        for (int i = 0; i < N; i++) {
            if (v[i0[i]] != v[i1[i]] || min(v[i0[i]], v[i1[i]]) != 1 || i == N - 1 || s[i] == s[i + 1]) {
                if (v[i0[i]] >= v[i1[i]]) {
                    v[i0[i]]--;
                    v[i1[i]]++;
                    ans[i] = 'A' + i1[i];
                    if (v[i0[i]] < 0) p = false;
                } else
                    v[i0[i]]++, v[i1[i]]--, ans[i] = 'A' + i0[i];
            } else {
                if (i0[i] == i0[i + 1] || i0[i] == i1[i + 1]) {
                    v[i0[i]]++;
                    v[i1[i]]--;
                    ans[i] = 'A' + i0[i];
                } else {
                    v[i0[i]]--;
                    v[i1[i]]++;
                    ans[i] = 'A' + i1[i];
                }
                if (min(v[i0[i]], v[i1[i]]) < 0) p = false;
            }
        }
    }
    if (p) {
        cout << "Yes" << endl;
        for (int i = 0; i < N; i++) cout << ans[i] << endl;
    } else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 7200
H,W = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k]+C[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += C[A[i][j]][1]

print(ans)

Measured memory_bytes: 9516
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long 
using namespace std;
struct node{
	int to,nxt;
}edge[200100];
int head[200100],cnt,dis[200100],Fa[200100],Far;
int n,x,y,S,T,degree[200100],maxn[200100];
void addedge(int x,int y){
	edge[++cnt].to=y;
	edge[cnt].nxt=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa,int depth){
	maxn[depth]=max(maxn[depth],degree[x]-1);
	for(int i=head[x];i;i=edge[i].nxt){
		int upup=edge[i].to;
		if(upup==fa)continue;
		dfs(upup,x,depth+1);
	}
}
void getfar(int x,int fa){
	dis[x]=dis[fa]+1;
	Fa[x]=fa;
	if(dis[x]>dis[Far])Far=x;
	for(int i=head[x];i;i=edge[i].nxt){
		int upup=edge[i].to;
		if(upup==fa)continue;
		getfar(upup,x);
	}
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<n;i++){
		scanf("%lld%lld",&x,&y);
		addedge(x,y);
		addedge(y,x);
		degree[x]++,degree[y]++;
	}
	getfar(1,0);
	S=Far;
	Far=0;
	getfar(S,0);
	T=Far;
	printf("%lld ",(dis[Far]+1)/2);
	if(dis[Far]%2==0){
		int root1=T,ans=0;
		while(dis[root1]!=dis[T]/2+1)root1=Fa[root1];
		int root2=Fa[root1];
		dfs(root1,root2,1);
		dfs(root2,root1,1); 
		int now=1;
		for(int i=1;i<=n;i++){
			ans=max(ans,now);
			now=now*maxn[i];			
		}
		printf("%lld\n",ans*2);
	}
	else{
		int root=T,ans=0;
		while(dis[root]!=dis[T]/2+1)root=Fa[root];
		degree[root]++;
		dfs(root,0,1);
		int now=1;
		for(int i=1;i<=n;i++){
			ans=max(ans,now);
			now=now*maxn[i];			
		}
		degree[root]--;
		for(int i=head[root];i;i=edge[i].nxt){
			int upup=edge[i].to;
			memset(maxn,0,sizeof(maxn));
			dfs(root,upup,1);
			dfs(upup,root,1);
			int sum=0,now=1;
			for(int i=1;i<=n;i++){
				sum=max(sum,now);
				now=now*maxn[i];			
			}
			ans=min(ans,sum*2);
		} 
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   sort(a.begin(), a.end(), greater<int>());
   int al, bob;
   al = bob = 0;
   for (int i = 0; i < n; i += 2) {
      al += a[i];
      if (i + 1 < n) {
         bob += a[i + 1];
      }
   }
   int ans = al - bob;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256