akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
    int K=int.Parse(Console.ReadLine());
      string[] str=Console.ReadLine().Split(' ');
      int[] z=new int[N];
      int ans=0;
      for(int i=0;i<N;i++){
        
		z[i]=int.Parse(str[i]);
        if(Math.Abs(K-z[i])<z[i]){
          ans+=2*(Math.Abs(K-z[i]));
        }else{
          ans+=2*z[i];
        }
      }Console.WriteLine(ans);


           }
  }

}

Measured memory_bytes: 13140
def main():
    n = int(input())
    s = str(n)
    if n % 10 == 0:
        a = 0
        for i in s:
            a += int(i)

        f = True
        for i in range(len(s)):
            if i == 0:
                pass
            else:
                if s[i] != "0":
                    f = False
                    break
        if f:
            if s[0] == "1":
                print(10)
            else:
                print(a)
        else:
            print(a)

    else:
        a = 0
        for i in s:
            a += int(i)
        print(a)

if __name__ == "__main__":
    main()

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

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

	auto x = div(a+b, 2);

	if(x.rem){
		cout << x.quot +1 <<endl;
	}else{
		cout << x.quot << endl;
	}
}


Measured memory_bytes: 256
a = input()
b = input()
c = input()

nxt="a"
while(True):
    if nxt=="a" and len(a)==0:
        print("A")
        break
    if nxt=="b" and len(b)==0:
        print("B")
        break
    if nxt=="c" and len(c)==0:
        print("C")
        break

    if nxt=="a":
        nxt = a[0]
        a = a[1:]
    elif nxt=="b":
        nxt = b[0]
        b = b[1:]
    elif nxt=="c":
        nxt = c[0]
        c = c[1:]

Measured memory_bytes: 3064
import sys
from collections import defaultdict, deque


def main():
    S = input()
    t = ['Sunny', 'Cloudy', 'Rainy']
    if S == t[0]:
        print(t[1])
    elif S == t[1]:
        print(t[2])
    else:
        print(t[0])


if __name__ == '__main__':
    main()


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

#define ll long long
#define fr first
#define se second

using namespace std;

const long long N = 2e6 + 7;

ll res, n, m, x, cnt, q = 1;
string s, str;
set < ll > st;
vector< string > v;
int main()
{
    /// freopen( "input.txt", "r", stdin );
    /// freopen( "output.txt", "w", stdout );
    cin >> n >> m;
    for ( int i=0; i<m; i++ ){
        cin >> x;
        for ( int j=0; j<x; j++){
            cin >> q;
            st.insert( q );
        }
    }
    cout << n  - st.size();
}


Measured memory_bytes: 3628
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)

using namespace std;

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

  int N;
  cin >> N;

  int A[100] = {};

  ll total = 1;
  ll ans = 1;
  REP(i, N) {
    cin >> A[i];
    total *= 3;
    if (A[i] % 2 == 0) {
      ans *= 2;
    }
  }

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


Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(n)]
max = b[0]+b[n-2]
a[0] = b[0]
a[n-1] = b[n-2]
for i in range(1,n-1):
    a[i] =min(b[i-1],b[i])
    max += a[i]
print(max)

Measured memory_bytes: 3064
#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()
{
    ll N;
    cin >> N;
    double sum = 0., a;
    rep(i, N)
    {
        cin >> a;
        sum += 1 / a;
    }
    cout << 1 / sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	string T, P; cin >> T >> P;
	for (size_t s = T.find(P); s != string::npos; s = T.find(P, s)) {
		printf("%d\n", s++);
	}
	return 0;
}

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

int main() {
    long long n;
    cin >> n;
    vector<int> nums;
    int end = sqrtl(n) + 1;
    for (int now = 2; now <= end; ++now) {
        int cnt = 0;
        while (n % now == 0) {
            cnt++; n /= now;
        }
        nums.push_back(cnt);
    }
    int ans = 0;
    if (n != 1) ans++;
    for (int i: nums) {
        int sum = i;
        int now = 1;
        while (now <= sum) {
            sum -= now;
            ans++;
            now++;
        }
    }
    cout << ans << endl;
}


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

#define    ll    long long int

int main( )
{
    int n, m, i, j, k;
    int b[22];
    int c = 0, res = 0, cnt = 0;
    cin >> n >> m >> c;
    for (i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (i = 0; i < n; i++) {
        res = c;
        for (j = 0; j < m; j++) {
            cin >> k;
            res += (b[j] * k);
        }
        if (res > 0) cnt++;
    }
    cout << cnt << '\n';
    return 0;
}




Measured memory_bytes: 256
while True:
      n, m = map(int, raw_input().split())
      if n == 0 and m == 0:
            break
      p = [ i+1 for i in range(n) ]
      np = n; a = 0
      while np > 1:
            a = (a+m-1)%len(p)
            p.pop(a)
            np -= 1
      print p[0]

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define forn(i, n) for(int i = 0; i < int__(n); i++) 
#define sz(a) int__(a.size())
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int x,int y){return y!=0 ? gcd(y,x%y) : x;}
 
int__ main() {
	fast;
	
	int n,W; cin >> n >> W;

	vi w(n+1),v(n+1);

	for(int i=1;i<=n;i++) cin >> w[i] >> v[i];

	vvi dp(n+1,vi (1e5+11,1e12));
	for(int i=0;i<=n;i++) dp[i][0] = 0;

	for(int i=1;i<=n;i++) {
		for(int j=1;j<=1e5+10;j++) {
			if(j >= v[i]) dp[i][j] = min(dp[i-1][j],w[i] + dp[i-1][j-v[i]]);
			else dp[i][j] = dp[i-1][j];
		}
	}

	for(int i=1e5+10;i>=0;i--) {
		if(dp[n][i] <= W) {cout << i << endl; break;}
	}
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n; cin >> n;
    map<int, int> odd, even;

    for(int i=1; i<=n; i++){
        int v; cin >> v;
        if(i%2 != 0) odd[v]++;
        else even[v]++;
    }

    pair<int, int> om1 = {0,0}, om2 = {0,0}, em1 = {0,0}, em2 = {0,0};

    for(auto itr=odd.begin(); itr!=odd.end(); itr++){
        if(itr->second >= om1.second){
            om2.first = om1.first;
            om2.second = om1.second;

            om1.first = itr->first;
            om1.second = itr->second;
        }
        else if(itr->second > om2.second){
            om2.first = itr->first;
            om2.second = itr->second;
        }
    }

    for(auto itr=even.begin(); itr!=even.end(); itr++){
        if(itr->second >= em1.second){
            em2.first = em1.first;
            em2.second = em1.second;

            em1.first = itr->first;
            em1.second = itr->second;
        }
        else if(itr->second > em2.second){
            em2.first = itr->first;
            em2.second = itr->second;
        }
    }

    if(em1.first != om1.first){
        cout << n/2-em1.second + n/2-om1.second << endl;
    }
    else cout << min(n/2-em1.second + n/2-om2.second, n/2-em2.second + n/2-om1.second) << endl;
}

Measured memory_bytes: 4992
let N = readLine()
let a = readLine()!.characters.split(" ").map{Int(String($0))!}
var dic = [Int : Int]()
for i in (a + a.map{$0+1} + a.map{$0-1}) {
    if dic[i] == nil {
        dic[i] = 0
    }
    dic[i]! += 1
}
print(dic.values.maxElement()!)

Measured memory_bytes: 10196
#include <bits/stdc++.h>
#define calc(x) swap((x)->son[1], (x)->son[2])
using namespace std;

char s[200010];

struct Node {
	int x, rev;
	Node *son[3];
	Node() {x = -1, son[0] = son[1] = son[2] = NULL, rev = 0;}
	void pushdown() {
		if (!rev) return ;
		son[0]->rev ^= 1, son[1]->rev ^= 1, son[2]->rev ^= 1;
		calc(son[0]), calc(son[1]), calc(son[2]);
		rev = 0;
	}
}pool[1500000], *CUR = pool;

Node *Build(int l, int r, int dep, int x) {
	if (l == r) {
		CUR->x = x;
		return CUR++;
	}
	Node *now = CUR++;
	int m1 = l + (r - l + 1) / 3 - 1;
	int m2 = l + (r - l + 1) / 3 * 2 - 1;
	now->son[0] = Build(l, m1, dep * 3, x);
	now->son[1] = Build(m1 + 1, m2, dep * 3, x + dep);
	now->son[2] = Build(m2 + 1, r, dep * 3, x + dep * 2);
	return now;
}

void Update(Node *T) {
	if (T->x != -1) return ;
	T->pushdown();
	swap(T->son[0], T->son[2]), swap(T->son[1], T->son[2]);
	Update(T->son[0]);
}

int ans[540000];

void print(Node *T, int dep, int x) {
	if (T->x != -1) {
		ans[T->x] = x;
		return ;
	}
	T->pushdown();
	print(T->son[0], dep * 3, x);
	print(T->son[1], dep * 3, x + dep);
	print(T->son[2], dep * 3, x + dep * 2);
}

int main () {
	int n; scanf("%d", &n);
	int N = 1;
	for (int i = 0; i < n; i++) {
		N *= 3;
	}
	N--;
	Node *T = Build(0, N, 1, 0);
	scanf("%s", s); int m = strlen(s);
	for (int i = 0; i < m; i++) {
		if (s[i] == 'R') Update(T);
		else {
			T->rev ^= 1;
			calc(T);
		}
	}
	print(T, 1, 0);
	for (int i = 0; i <= N; i++) {
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 53220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, N);
  
  if(N % 2 == 0) {
    fin(0.5);
  } else {
    fin((double)(N / 2 + 1)/N);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
	ll a;
	cin >> a;
	cout << (1^a) << endl;
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i, n) {
        int a;
        cin >> a;
        q.push(a);
    }

    rep(i, m) {
        int a = q.top(); q.pop();
        q.push(a/2);
    }

    ll ans = 0;
    rep(i, n) {
        ans += q.top(); q.pop();
    }

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

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

using namespace std;

int main ()
{
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 == 1) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 2) {
        if (d1 == 28)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 3) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 4) {
        if (d1 == 30)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 5) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 6) {
        if (d1 == 30)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 7) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 8) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 9) {
        if (d1 == 30)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 10) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 11) {
        if (d1 == 30)
            cout << 1 << endl;
        else cout << 0 << endl;
    }
    else if (m1 == 12) {
        if (d1 == 31)
            cout << 1 << endl;
        else cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

struct edge{
    ll u, v;
    edge(){u=0; v=0;}
    edge(ll _u, ll _v){
        u = _u; v = _v;
    }
};

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    vector<vll> G(N);
    map<pll, ll> c;
    REP(i, N-1){
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        c[make_pair(a[i], b[i])] = 0;
    }
    vb checked(N, false);
    queue<pair<edge, ll> > que;
    
    que.push(make_pair(edge(0, 0), 0));
    while(!que.empty()){
        auto x = que.front(); que.pop();
        ll u = x.first.u, v = x.first.v, color = x.second;
        checked[u] = true;
        ll use_color = 1;
        for(auto to: G[v]){
            //* to is neighbour of v
            if(checked[to]==false){
                if(use_color == color)
                    use_color ++;
                que.push(make_pair(edge(v, to), use_color));
                c[make_pair(min(v, to), max(v, to) )]= use_color;
                use_color++;
            }
        }
    }
    ll K = 0;
    REP(i, N-1){
        K = max(K, c[make_pair(a[i], b[i])]);
    }
    cout << K << endl;
    REP(i, N-1){
        cout << c[make_pair(a[i], b[i])] << endl;
    }
    

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        a[i]--; b[i]--;
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 14708
#include <bits/stdc++.h>
using namespace std;
int x;string s;
int main(){
	cin>>x>>s;
	for (int i=0;i<s.size();i++){
		for (int j=0;j<x;j++){
			if (s[i]!='Z')s[i]++;
			else s[i]='A';
		}
	}
cout<<s;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();

        if (a == b)
        {
        System.out.println(c);
        }
        if (a==c)
        {
            System.out.println(b);
        }
        if (b==c)
        {
            System.out.println(a);
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 22356
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
int N,K;
void in(vector<vector<int> >&a)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)a[i][j]=0;
	}
	int h;cin>>h;
	vector<int>s(N);
	iota(s.begin(),s.end(),0);
	for(;--h;)
	{
		for(int i=0;i<N-1;i++)
		{
			int u;cin>>u;
			if(u)swap(s[i],s[i+1]);
		}
	}
	for(int i=0;i<N;i++)
	{
		a[i][s[i]]=1;
	}
}
vector<vector<int> >mul(const vector<vector<int> >&a,const vector<vector<int> >&b)
{
	vector<vector<int> >ans(N,vector<int>(N,0));
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<N;k++)ans[i][j]+=a[i][k]*b[k][j];
		}
	}
	return ans;
}
vector<vector<int> >power(const vector<vector<int> >&a,int n)
{
	vector<vector<int> >ans(N,vector<int>(N,0));
	vector<vector<int> >A(a);
	for(int i=0;i<N;i++)ans[i][i]=1;
	while(n)
	{
		if(n&1)
		{
			ans=mul(ans,A);
		}
		n/=2;
		A=mul(A,A);
	}
	return ans;
}
string s;int id;
vector<vector<int> >f(const vector<vector<vector<int> > >&A)
{
	vector<vector<int> >ans(N,vector<int>(N,0));
	for(int i=0;i<N;i++)ans[i][i]=1;
	int now=0;
	for(;id<s.size();id++)
	{
		if(s[id]=='(')
		{
			id++;
			ans=mul(power(f(A),now>0?now:1),ans);
			now=0;
		}
		else if(s[id]>='A'&&s[id]<='Z')
		{
			ans=mul(power(A[s[id]-'A'],now>0?now:1),ans);
			now=0;
		}
		else if(s[id]>='0'&&s[id]<='9')
		{
			now=now*10+s[id]-'0';
		}
		else if(s[id]==')')
		{
			break;
		}
	}
	return ans;
}
main()
{
	cin>>N>>K;
	vector<vector<vector<int> > >A(26,vector<vector<int> >(N,vector<int>(N)));
	for(int i=0;i<K;i++)
	{
		char c;cin>>c;
		in(A[c-'A']);
	}
	int E;cin>>E;
	for(;E--;)
	{
		cin>>s;
		id=0;
		vector<vector<int> >a=f(A);
		for(int i=0;i<N;i++)
		{
			if(i)cout<<" ";
			for(int j=0;j<N;j++)if(a[i][j]==1)cout<<j+1;
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3304
from itertools import product
from collections import deque
INF = 1e7
def main():
    H, W = map(int, input().split())
    ch, cw = map(lambda x: int(x)+1, input().split())
    dh, dw = map(lambda x: int(x)+1, input().split())
    S = [["#"]*(W+4) for _ in range(H+4)]
    whites = [] #　道であるindex
    for i in range(2, H+2):
        tmp = input()
        for j in range(2, W+2):
            S[i][j] = tmp[j-2]
            if S[i][j] == ".":
                whites.append((i,j))

    dxdy = [(1,0), (-1,0), (0,1), (0,-1)]
    magic = list(product(range(-2, 3), repeat=2))
    magic.remove((0, 0))
    for to_remove in dxdy:
        magic.remove(to_remove)
    
    # graph = {idx: deque() for idx in whites}
    # for idx in whites:
    #     x = idx[0]
    #     y = idx[1]
    #     for dx, dy in dxdy:
    #         if S[x+dx][y+dy] == ".":
    #             graph[idx].append((x+dx, y+dy))
    # graph2 = {idx: deque() for idx in whites}
    # for idx in whites:
    #     x = idx[0]
    #     y = idx[1]
    #     for mx, my in magic:
    #         if S[x+mx][y+my] == ".":
    #             graph2[idx].append((x+mx, y+my))
    
    def bfs(u,v):
        dist = [[INF] * (W+4) for _ in range(H+4)] #indexed from 1
        # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1
        queue = deque()
        # seen[u][v] = 1
        dist[u][v] = 0
        queue.append((u,v))
        while queue:
            p, q = queue.popleft()
            # if not graph[(p,q)]:
            #     queue.popleft()
            #     continue
            # g,h = graph[(p,q)].popleft()
            # if seen[g][h]:
            #     continue
            # seen[g][h] = 1
            # dist[g][h] = min(dist[g][h], dist[p][q])
            for dx, dy in dxdy:
                g = p+dx
                h = q+dy
                if S[g][h]=="." and dist[g][h] > dist[p][q]:
                    dist[g][h] = dist[p][q]
                    queue.appendleft((g,h))
            for dx, dy in magic:
                g = p+dx
                h = q+dy
                if S[g][h]=="." and dist[g][h] > dist[p][q]+1:
                    dist[g][h] = dist[p][q]+1
                    queue.append((g,h))
            # dist[g][h] = min(dist[g][h], dist[p][q]+1)
            # queue.append((g,h))
        return dist

    D = bfs(ch, cw)
    ans = D[dh][dw]
    if ans == INF:
        print(-1)
    else:
        print(ans)

if __name__ == "__main__":
    main()

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

int main() {
  string s;
  cin >> s;
  vector<char> vc;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '1') vc.push_back('1');
    else if(s[i] == '0') vc.push_back('0');
    else{
       if(!vc.empty()) vc.pop_back();
    }
  }
  for(int i = 0; i < vc.size(); i++){
    cout << vc[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
def solve():
    N,K = map(int,input().split())
    S = input()

    one_zero = []
    target = '1'
    cnt = 0
    for i in range(N):
        if S[i] != target:
            one_zero.append(cnt)
            target = '1' if target == '0' else '0'
            cnt = 1
        else:
            cnt += 1
    else:
        one_zero.append(cnt)
        if target == '1':
            one_zero.append(0)
    
    start = 0
    end = 2*K+1
    sm = sum(one_zero[start:end])
    ans = sm
    while end < len(one_zero)*2:
        sm = sm - sum(one_zero[start:start+2]) + sum(one_zero[end:end+2])
        ans = max(ans,sm)
        start += 2
        end += 2

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 45936
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    vector<int> alice(101,0);
    vector<int> bob(101,0);

    for(int i=a; i<b; i++){
        alice[i]=1;
    }
    for(int i=c; i<d; i++){
        bob[i]=1;
    }

    int sum=0;
    for(int i=0;i<=100;i++){
        if(alice[i]==1 && bob[i]==1){
            sum++;
        }
    }

    cout << sum << endl;
    return 0;
}

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

int main(void){
  string ref1 = "";
  string ref2 = "";
  string a;
  cin >> a;

  for (int i = 0;i < a.length(); i++){
    if (i %2 ==0){
      ref1 = "1" + ref1;
      ref2 = "0" + ref2;
    }
    else{
      ref2 = "1" + ref2;
      ref1 = "0" + ref1;
      // ref2 = ref2 + pow(10, i);
    }
  }

  int count1 = 0;
  int count2 = 0;

  for (int i = 0; i < ref1.length(); i++){
    if(ref1[i] != a[i]){
      count1 = count1 + 1;
    }  
  }  

  for (int i = 0; i < ref2.length(); i++){
    if(ref2[i] != a[i]){
      count2 = count2 + 1;
    }  
  }

  if (count1 < count2){
    cout << count1 << endl;
  }
  else{
    cout << count2 << endl;
  }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    for(int i=1;i<100;i++){
        ll m = 1000*i;
        if(m>=N){
            cout << m -N << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;

int main(){
    ll x;
    cin>>x;
    int ans=INF;
    while(x>0){
        ans=min((ll)ans,abs(753-x%1000));
        x/=10;
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n;
    ll ans=0;
    scanf("%lld",&n);
    ll t[n];
    rep(i,0,n){
        scanf("%lld",&t[i]);
    }
    ans=t[0];
    rep(i,0,n){
        ans = lcm(ans,t[i]);
    }

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


Measured memory_bytes: 128
using System;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ');
			long a = long.Parse(input[0]);
			long b = long.Parse(input[1]);
			long k = long.Parse(input[2]);

			if (a >= k)
			{
				a -= k;
			}
			else if (a + b >= k)
			{
				b -= (k - a);
				a = 0;
			}
			else
			{
				a = 0;
				b = 0;
			}
			Console.WriteLine(a + " " + b);
		}
	}
}


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


int main() {
	int k,a,b;
    cin>>k;
    cin>>a>>b;
    if(a%k==0 || b%k==0) cout<<"OK"<<endl;
    else if(a/k!=b/k) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

char grid[1002][1002];

int power(int n, int x)
{
	if (x == 0)
		return 1;

	int small = power(n, x / 2) % mod;
	small = (small * small) % mod;

	if (1 & x)
		small = (n * small) % mod;

	return small;
}

bool isPowerOfTwo(int n)
{
	return n && (!(n & (n - 1)));
}


int dp[3002][3002][2];

int solve(int *a, int i, int j, bool turn)
{
	if (i > j)
		return 0;
	if (dp[i][j][turn] != -1)
		return dp[i][j][turn];
	if (turn == 1)
	{
		return dp[i][j][turn] = max(a[i] + solve(a, i + 1, j, 0), a[j] + solve(a, i, j - 1, 0));
	}
	else
		return dp[i][j][turn] = min(solve(a, i + 1, j, 1), solve(a, i, j - 1, 1));

}

int32_t main()
{
	//d_m_c();

	int n;
	cin >> n;

	int sum = 0;

	memset(dp, -1, sizeof dp);
	int a[n + 1];

	for (int i = 1; i <= n; i++)
	{	cin >> a[i];
		sum = sum + a[i];
	}

	int X = solve(a, 1, n, 1);
	int Y = sum - X;

	cout << (X - Y) << endl;

	return 0;
}

Measured memory_bytes: 141824
#include <iostream>
using namespace std;
typedef long long LL;
const int MAX_N=100005;
LL a[MAX_N],n,k;
int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++)
		cin >> a[i];
	LL x=0;
	for (int i=62; i>=0; i--) {
		LL cnt=0;
		for (int j=0; j < n; j++)
			cnt += (bool)(a[j] & (1LL << i));
		if (2*cnt < n && (x | (1LL << i)) <= k)
			x |= 1LL << i;
	}
	LL res=0;
	for (int i=0; i < n; i++)
		res += x ^ a[i];
	cout << res << endl;
}


Measured memory_bytes: 1024
N = int(input())

a = 0
b = 0
ans = 0
ab = 0

for i in range(N):
    s = input()
    ans += s.count('AB')
    if s[0] == 'B':
        b += 1
        if s[-1] == 'A':
            ab += 1
    if s[-1] == 'A':
        a += 1

if a == b == ab:
    if ab > 0:
        ans += ab - 1
else:
    ans += min(a, b)

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
using ll = long long;
using db = long double;
const int N = 1 << 17, MOD = 1e9 + 7;
ll A, B, C, D;
ll LCM(ll x, ll y){
  return x / __gcd(x,y) * y;
}
ll get(ll x){
  return x - (x / C + x / D - x / LCM(C,D));
}
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);cin.tie(0);
#endif // ONLINE_JUDGE
  int n;  cin >> n;
  vector<pair<int,int>> vp(n);

  for(auto & x : vp)
    cin >> x.second >> x.first;
  sort(vp.begin(),vp.end());

  int curTime = 0;

  for(auto x : vp){
    curTime += x.second;
    if(curTime > x.first){
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";

  return 0;
}


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

#define N 100

void push(int);
int pop(void);
/*int isEmpty(void);
int isFull(void);*/

int S[N];
int top=0;

int main()
{
    char s[N];
    int m,n;

    while(scanf("%s",s) != EOF ){
        if(s[0]=='+'){
            m=pop();
            n=pop();
            push(m+n);
        }
        else if(s[0]=='-'){
            m=pop();
            n=pop();
            push(n-m);
        }
        else if(s[0]=='*'){
            m=pop();
            n=pop();
            push(m*n);
        }
        else{
            push(atoi(s));
        }
    }

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

return 0;
}        

/*int isEmpty(){
    if(top==0) return 0;
}

int isFull(){
    if(top >= N-1) return 0;
}*/

void push(int x){
    top++;
    S[top]=x;
}

int pop(){
    top--;
    return S[top+1];
}

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

int main(){
    int n; cin>>n;
    int t=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int k=4*i+7*j;
            if(k==n){
            t=1;
            break;
            }
        }
    }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	if(n & 1){
		printf("%d\n", (n - 1) * (n - 1) / 2);
		for(int i = 2; i <= n / 2; ++i){
			for(int j = 1; j < i; ++j){
				printf("%d %d\n", j, i);
				printf("%d %d\n", n - j, i);
				printf("%d %d\n", j, n - i);
				printf("%d %d\n", n - j, n - i);
			}
		}
		for(int i = 1; i < n; ++i) printf("%d %d\n", i, n);
	}else{
		printf("%d\n", n * (n - 2) / 2);
		for(int i = 2; i <= n / 2; ++i){
			for(int j = 1; j < i; ++j){
				printf("%d %d\n", j, i);
				printf("%d %d\n", n - j + 1, i);
				printf("%d %d\n", j, n - i + 1);
				printf("%d %d\n", n - j + 1, n - i + 1);
			}
		}
	}
}


Measured memory_bytes: 128
n, k = map(int,input().split())
r, s, p = map(int, input().split())
t = input()

pt = [0 for i in range(n)]

for i in range(n):
  if t[i] == "r":
    pt[i] = p
  elif t[i] == "s":
    pt[i] = r
  else:
    pt[i] = s
  if i >= k and t[i] == t[i - k] and pt[i - k] > 0:
    pt[i] = 0

print(sum(pt))

Measured memory_bytes: 4212
mod_base = (10 ** 9) + 7
n, k = map(int, input().split(" "))
a = map(int, input().split(" "))
sa = sorted(a, reverse=True)

fac = fac_inv = inv = list()


def comb_init(n_in, mod):
    global fac, fac_inv, inv
    fac = [1 for x in range(0, n_in + 1)]
    fac_inv = [1 for x in range(0, n_in + 1)]
    inv = [1 for x in range(0, n_in + 1)]
    # fac[0] = fac[1] = 1
    # fac_inv[0] = fac_inv[1] = 1
    # inv[0] = inv[1] = 1

    for i in range(2, n_in + 1):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        fac_inv[i] = fac_inv[i - 1] * inv[i] % mod


def comb(n_in, r, mod):
    if n_in < r:
        return 0
    elif n_in < 0 or r < 0:
        return 0
    else:
        return fac[n_in] * (fac_inv[r] * fac_inv[n_in - r] % mod) % mod


comb_init(n, mod_base)

sum_max = 0
sum_min = 0
for i in range(0, n):
    sai = sa[i]

    if (n - i - 1) >= (k - 1):
        # print("max: sai:%d comb:%d" % (sai, comb(n - i - 1, k - 1)))
        sum_max = (sum_max + sai * comb(n - i - 1, k - 1, mod_base)) % mod_base

    if i >= (k - 1):
        sum_min = (sum_min + sai * comb(i, k - 1, mod_base)) % mod_base
        # print("min: sai:%d comb:%d" % (sai, comb(i, k - 1)))

# print("%d %d" % (sum_max, sum_min))
print((sum_max - sum_min) % mod_base)


Measured memory_bytes: 18904
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc =new Scanner(System.in);
		
		while(true){
			int n =sc.nextInt();
			if(n==0){break;}
			int[] scores=new int[n];
			for(int i=0;i<scores.length;i++){
				scores[i]=sc.nextInt();
			}
			int max=0,ave=0;
			for(int i=0;i<scores.length;i++){
				if(max<scores[i]){
					max=scores[i];
				}
			}
			int min=scores[0];
			for(int i=1;i<scores.length;i++){
				if(min>scores[i]){
					min=scores[i];
				}
			}
			int sum=0,count=0;
			for(int i=0;i<scores.length;i++){
				if(scores[i]!=max && scores[i]!=min){
					sum=sum+scores[i];
					count++;
				}else if(scores[i]==max){
					max=max+1;
				}else{
					min=min-1;
				}
			}
			if(count!=0){
			ave=sum/count;
			}
			System.out.println(ave);
		}
	}
}

Measured memory_bytes: 21136
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    N, K = ILI()

    ans = 0.0
    for i in range(1,N+1):  # サイコロの出た目
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        win = True  # 勝ち続けているか
        while True:
            if K <= scr:  # 勝ち
                break
            elif 0 < scr < K:
                scr *= 2
                pb *= 0.5
            else:  # 負け
                TAST(False, "ここには来ない")
                scr = 0
                win = False
                break
        if win:
            ans += pb / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n], ans = 0;;
    for(int i=0;i<n;i++){

    	cin >> a[i];
    	ans += a[i];
    }
    cout << ans - n << endl;
    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,mc=0;
	ll res=0,mn;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		ll t=0;
		cin>>t;
		if(t<0)mc++;
		mn=i==0?t:min(abs(mn),abs(t));
		res+=abs(t);
	}
	if(mc%2)
	{
		res-=mn*2;
	}
	cout<<res<<endl;

}

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

typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<P> R(N), B(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        R[i] = P(a, b);
    }
    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        B[i] = P(c, d);
    }
    sort(R.begin(), R.end());
    sort(B.begin(), B.end());
    vector<bool> used(N);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int max_y = -1;
        int min_j = -1;
        for (int j = 0; j < N; j++) {
            if (B[i].first < R[j].first || B[i].second < R[j].second) {
                continue;
            }
            if (max_y < R[j].second && !used[j]) {
                max_y = R[j].second;
                min_j = j;
            }
        }
        if (min_j >= 0) {
            used[min_j] = true;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    }

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
const ll INF = 1000000000000000000;
const ll MOD = 1000000000 + 7;
const int MAX_N = 20 + 2;
ll a[MAX_N][MAX_N];
ll dp[1 << MAX_N];
int N;

int popcount(int S) {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S >> i & 1) cnt++;
  }
  return cnt;
}


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

  cin >> N;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  dp[0] = 1;
  
  for (int S = 0; S < (1 << N); S++) {
    int i = popcount(S);
    
    for (int j = 0; j < N; j++) {
      if (!(S >> j & 1) && a[i][j] == 1) {
	int nextS = S | (1 << j);
	dp[nextS] += dp[S];
	dp[nextS] %= MOD;
      }
    }
  }

  cout << dp[(1 << N) - 1] << endl;
  
  return 0;
}



Measured memory_bytes: 19508
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<ll>cur(202020);
vector<int>e[202020];

void dfs(int now,int p) {
	cur[now] += ((p == -1) ? 0:cur[p]);
	fore(x, e[now]) {
		if (x != p) {
			dfs(x,now);
		}
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		e[a].pb(b);
		e[b].pb(a);
	}

	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		p--;
		cur[p] += x;
	}
	dfs(0,-1);
	for (int i = 0; i < n; i++) {
		cout << cur[i] << " ";
	}
	puts("");
	return 0;
}

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

using namespace std;

int main() {
    int H, W;

    while (cin >> H >> W) {
        if (H == 0 && W == 0) break;

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (h % 2 == 0) {
                    if (w % 2 == 0) {
                        cout << '#';
                    } else {
                        cout << '.';
                    }
                } else {
                    if (w % 2 == 0) {
                        cout << '.';
                    } else {
                        cout << '#';
                    }
                }
            }
            cout << endl;
        }

        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    long ans = 1;
    for(int i = 0; i < N; i++){
      long sec = Long.parseLong(sc.nextLine());
      ans = lcm(ans, sec);
    }
    System.out.println(ans);
  }
  static long gcd(long a, long b){
    if(b > a){
      return gcd(b, a);
    }
    if(b == 0){
      return a;
    }
    return gcd(b, a%b);
  }
  
  static long lcm(long a, long b){
    return a*(b/gcd(a,b));
  }
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<ll> x(n), y(n), h(n);
    int idx = -1;
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0) idx = i;
    }

    ll ans_x = -1, ans_y = -1, ans_h = -1;
    for(ll i = 0; i <= 100; i++) {
        for(ll j = 0; j <= 100; j++) {
            ll H = abs(i-x[idx]) + abs(j-y[idx]) + h[idx];
            // 矛盾が起こっていないかチェック
            bool flag = true;
            rep(k, n) {
                if(h[k] != 0 && H != abs(i-x[k]) + abs(j-y[k]) + h[k]) flag = false;
                if(h[k] == 0 && H - abs(i-x[k]) - abs(j-y[k]) > 0) flag = false;
            }
            if(flag) ans_x = i, ans_y = j, ans_h = H;
        }
    }
    
    cout << ans_x << " " << ans_y << " " << ans_h << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	string S;
	cin >> S;
	int N = S.back() - '0';
	if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) puts("hon");
	else if (N == 3) puts("bon");
	else puts("pon");
	return 0;
}


Measured memory_bytes: 3588