akhauriyash/Code-Regression huggingface dataset:
// SmartCoder
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000000000000ll
const long long MAXN = 1e7;
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll A, B, N;
    cin >> A >> B >> N;
    cout << A * min(B - 1, N) / B << endl;
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/perl

my $s = <STDIN>;
$s =~ s/[\x00-\x20]+$//ios;

my $n = length($s);
my $n2 = ($n - 1)/2;
my $n3 = int($n2 / 2);

#print "$n $n2 $n3\n";

my $res = 'Yes';
for( my $i = 0; $i<$n3 ; $i++){
  my $c1 = substr($s,$i,1);
  my $c2 = substr($s,$n2-1-$i,1);
  my $c3 = substr($s,$n2+1+$i,1);
  my $c4 = substr($s,$n-1-$i,1);
  #print "$c1 $c2 $c3 $c4\n";
  if( ( $c1 ne $c2 ) or ( $c1 ne $c3 ) or ( $c1 ne $c4 ) ){
    $res = 'No';
    last;
  }
}
#print "ho $res\n";
if( $n3 * 2 != $n2 ){
  my $c1 = substr($s,$n3,1);
  my $c2 = substr($s,$n2 + 1 +$n3,1);
  if( $c1 ne $c2 ){
    $res = 'No';
  }
}
print "$res\n";



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

#define fi first
#define se second

const int N = 3030;
const long long mod = 1e9 + 7;

using namespace std;

int n;
double d[N + N];
double f[N + N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        d[N] = 1.0;
        for(int i = 1; i <= n; i++){
                double p;
                cin >> p;
                for(int j = 1; j + 1 < N + N; j++){
                        f[j] = d[j - 1] * p + d[j + 1] * (1 - p);
                }
                for(int j = 1; j < N + N; j++){
                        d[j] = f[j];
                }
        }
        double res = 0;
        for(int i = N + 1; i < N + N; i++){
                res += d[i];
        }
        cout << fixed << setprecision(9) << res << "\n";
}



Measured memory_bytes: 384
field = input()

#%%
idxes = [] # \の位置を管理。一個/が追加されるたびに、その部分は水たまりになれるので、後ろからpopされる
v_lakes = [] # （その水たまりの最も左の\の位置、その水たまりの現時点での面積）の組を格納

for i, f in enumerate(field):
    if f == '\\':
        idxes.append(i) # \の位置を記録
    elif f == '/' and len(idxes) > 0:
        j = idxes.pop() # 最後尾の\の位置を抜き出す
        v = i - j   # \/間の長さがテンポラリの面積vに対応
        # 可能であるなら面積を統合する処理。螺旋本の19の面積みたいに、内側に2つ水たまりができるけどもっと大きく統合できるパターンがある
        # 今回新しく積み上げたj が すでに格納されてる水溜りの左端（v_lakes[-1][0]）よりも、小さい（より左側にある）場合は水溜りを統合してもよい
        while len(v_lakes) > 0 and v_lakes[-1][0] > j:
            v += v_lakes.pop()[1] # 統合する水溜りをpopして加える
        v_lakes.append((j, v))

ans = [v[1] for v in v_lakes]
print(sum(ans))
print(len(ans), *ans)


Measured memory_bytes: 6508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;cin>>s;
  if(s==1||s==2)cout<<4<<endl;
  else{
    int i=1;
    while(s!=1){
      if(s%2==0)s/=2;
      else s=s*3+1;
      i++;
    }
    cout<<i+1<<endl;
  }
}
      

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




LL cnt[62][300002];

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    LL i,j,n,x,y;
    cin >> n;
    LL a[n+1],ans=0;
    const LL mod=1e9+7;
    for(i=1;i<=n;i++)cin >> a[i];
    for(i=0;i<61;i++)
    {
        for(j=1;j<=n;j++)
        {
            cnt[i][j]=cnt[i][j-1];
            if(a[j] & (1LL << i))++cnt[i][j];
        }
    }
    for(i=0;i<61;i++)
    {
        for(j=1;j<n;j++)
        {
            x=cnt[i][j]-cnt[i][j-1];
            if(x == 1)y=(n-j)-(cnt[i][n]-cnt[i][j]);
            else y=cnt[i][n]-cnt[i][j];
            ans+=y*((1LL << i)%mod);
            ans%=mod;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 145920
// 解説PDFそのまま
//
// 2つの文字列について、その相対位置ごとに矛盾があるかないかを判定する
// 配列を用意するのがとても賢い

#include <iostream>
#include <string>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define M 2000

bool ab[100000],ac[100000],bc[100000];

bool match(char c1, char c2){
    return (c1 == '?' || c2 == '?' || c1 == c2);
}

int main(void){
    int i,j;

    string a,b,c;
    cin >> a >> b >> c;

    int A = a.length();
    int B = b.length();
    int C = c.length();

    constexpr int offset = 50000;

    // ab[i]: 文字列aに対して文字列bをi個分右に配置したときに
    //        矛盾が生じるなら1となる配列
    //        ただし、iが負の数になってもよいようoffset分下駄を履かせる
    REP(i,A) REP(j,B) if(!match(a[i], b[j])) ab[i-j+offset] = true;
    REP(i,A) REP(j,C) if(!match(a[i], c[j])) ac[i-j+offset] = true;
    REP(i,B) REP(j,C) if(!match(b[i], c[j])) bc[i-j+offset] = true;

    int ans = 3 * M;
    // 文字列aを基準として、bをi個右にずらす
    for(i=-2*M; i<=2*M; i++) { 
        // 文字列aを基準として、cをj個右にずらす
        for(j=-2*M; j<=2*M; j++) {
            // 矛盾がないなら配置できる
            if(!ab[i+offset] && !ac[j+offset] && !bc[j-i+offset]) {
                // 文字列a, b, cどれかの左端・右端をそれぞれ計算
                int L = min(0, min(i, j));
                int R = max(A, max(B + i, C + j));
                ans = min(ans, R - L);
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, j, ans=0, pro, tas;
    cin >> n;
    vector<long long> a(n), rui(n+1);
    rui.at(0)=0;
    for(i=0;i<n;i++){
        cin >> a.at(i);
        rui.at(i+1)=rui.at(i)+a.at(i);
        rui.at(i+1);
        
    }
    for(i=0;i<n-1;i++){
        tas = (rui.at(n)-rui.at(i+1));
        tas%=1000000007;
        if(tas<0) tas+=1000000007;
        pro=a.at(i)*tas;
        pro%=1000000007;
        ans+=pro;
        ans%=1000000007;
    }

    cout << ans <<endl;
}

Measured memory_bytes: 6412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll mod = 10651, N = 20;
ll mn = 1e9, n;

ll f(int k) {
	int res = 0;
	while (k) {
		res += k % 10;
		k /= 10;
	}
	return res;
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++)
		mn = min(mn, f(i) + f(n - i));
	cout << mn;
}

Measured memory_bytes: 256
K, N = map(int, input().split(" "))
A_list = [int(i) for i in input().split()]
max_diff = -1

for i in range(0, len(A_list)):
  if i == len(A_list)-1:
    if max_diff < (K-A_list[i]+A_list[0]):
      max_diff = K-A_list[i]+A_list[0]
  else:
    if max_diff < (A_list[i+1] - A_list[i]):
      max_diff = A_list[i+1] - A_list[i]

print(K - max_diff)


Measured memory_bytes: 24948
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

string s, t, u;
int n, m;

int main() {
    cin >> s >> t >> n >> m >> u;
    if (s == u) printf("%d %d\n", n - 1, m);
    else printf("%d %d\n", n, m - 1);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int back = 26;
  string ans="";
  for(int i=0;i<S.size();i++){
    if(N+(int) S[i] <= 90) ans += (char) (S[i] + N);
    else ans += (char) (S[i] - back + N);
  }
  cout << ans << endl;
}
  




Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main(){
    long L0=2, L1=1, tmp;
    int N;
    cin >> N;
    if (N==1){
        cout << L1 << endl;
        return 0;
    }

    for (int i = 1; i < N; i++) {
        tmp = L1;
        L1 += L0;
        L0 = tmp;
    }
    cout << L1 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <cassert>
#include <memory>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    int N;
    cin>>N;

    vint A;
    int X=0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.pb(a);
        X^=a;
    }

    for(int i=0;i<N;i++)
        cout<<(A[i]^X)<<(i==N-1?"\n":" ");


    return 0;
}


Measured memory_bytes: 4256
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

#define MAX 10000
vector<int> A,B(2000000,0),C(MAX,0);

int main(){
	int n,temp;
	
	scanf("%d",&n);
	A.push_back(0);
	for(int i=1;i<=n;i++){
		scanf("%d",&temp);
		A.push_back(temp);
	}
	for(int i=1;i<=n;i++){
		C[A[i]]++;
	}
	for(int i=1;i<MAX;i++){
		C[i]=C[i]+C[i-1];
	}
	for(int i=1;i<=n;i++){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
	printf("%d",B[1]);
	for(int i=2;i<=n;i++){
		printf(" %d",B[i]);
	}
	printf("\n");
}

Measured memory_bytes: 19048
#include <iostream>
#define N 100

using namespace std;

int main(int argc, char const *argv[]) {
    int n, u, k, v;
    int A[N][N] = {0};

    cin >> n;
    for (int j = 0; j < n; j++){
        cin >> u >> k;
        for (int i = 0; i < k; i++){
            cin >> v;
            A[u-1][v-1] = 1;
        }
    }
    for (int i = 0; i < u; i++){
        for (int j = 0; j < u - 1; j++){
            cout << A[i][j] << ' ';
        }
        cout << A[i][u-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    vector<double> h(N);
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    int ans = 0,tmp = 0;
    for (int i = 1; i < N; i++){
        if (h[i-1] >= h[i]){
            tmp++;
        } else {
            tmp = 0;
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
# ある学校には、N人の生徒がいます。
# 生徒たちをいくつかのグループに分け、グループごとにあるテーマについて話し合ってもらうこととなりました。
# あなたは、2人以下のグループだと効果的な話し合いが出来ないと考えており、なるだけ多くのグループを
# 3人以上にしたいです。生徒たちを上手く分けて、3人以上のグループの数を最大化してください。

# 標準入力から生徒数 N を取得する
input_num = int(input())

# 取得した N人から、3人以上のグループが最大数になるよう算出して出力する
result = int(input_num / 3)
print(result)


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define x first
#define y second
const int M=1e6+7;



int main() {
    ll n;
    cin>>n;
    vector<pair<ll,ll>> p(n);
    for(int i=0;i<n;i++)
        cin>>p[i].y>>p[i].x;
    sort(all(p));
    ll cur=0;
    for(auto i:p)
    {
        if(cur+i.y>i.x)
        {
            cout<<"No";
            return 0;
        }
        cur+=i.y;
    }
    cout<<"Yes";


}



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

int main() {
  int N; cin >> N;
  vector<int> A(N); for (int i =0; i<N; i++) cin >> A.at(i);
  
  int maxA =0; int secondMaxA =0; int maxCount =0; int maxPoint =0;
  for (int i =0; i<N; i++) {
    maxA = max(A.at(i),maxA);
  }
  for (int i =0; i<N; i++) {
    if (A.at(i) == maxA) {
      maxCount++;
      maxPoint = i;
      if (maxCount >= 2) {
        break;
      } else {
        continue;
      }
    }
    secondMaxA = max(A.at(i),secondMaxA);
  }
  for (int i =0; i<N; i++) {
    if (maxCount ==1 && i == maxPoint) {
      cout << secondMaxA << endl;
    } else {
      cout << maxA << endl;
    }
  }
}

Measured memory_bytes: 4060
import sys
sys.setrecursionlimit(4100000)


def dfs(cy, cx):
    # 一回走らせたら一つの島が消滅すると考える
    if not (cy < 0 or cy >= H or cx < 0 or cx >= W or gridgraph[cy][cx] == "0"):
        gridgraph[cy][cx] = "0"
        for dy, dx in adjacent:
            ny, nx = cy+dy, cx+dx
            dfs(ny, nx)


adjacent = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    gridgraph = [list(map(str, input().split())) for _ in range(H)]
    ans = 0
    for i in range(H):
        for j in range(W):
            if gridgraph[i][j] == "1":
                dfs(i, j)
                ans += 1
    print(ans)



Measured memory_bytes: 7944
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  n = get_int
  if n % 2 == 0
    puts 0.5
  else
    m = n / 2 + 1.0
    puts (m/n)
  end
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include <stdio.h>

int main(){
    int h1,m1,h2,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);

    int benkyoTime = 0;
    benkyoTime = (60*h2 + m2) - (60*h1 + m1);

    if(benkyoTime>k){
        printf("%d",benkyoTime - k);
    }else{
        printf("0");
    }

}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    set<int> d;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        d.insert(tmp);
    }

    cout << d.size() << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int dp[101][4][4][4];

int main(){
  int n; cin >> n;
  int ans = 0;
  int mod = 1000000007;
  dp[0][3][3][3] = 1;
  rep(len, n){
    rep(c1, 4){
      rep(c2, 4){
        rep(c3, 4){
          rep(a, 4){
            if(a == 2 && c1 == 1 && c2 == 0) continue;
            if(a == 2 && c1 == 0 && c2 == 1) continue;
            if(a == 1 && c1 == 2 && c2 == 0) continue;
            if(a == 2 && c1 == 1 && c3 == 0) continue;
            if(a == 2 && c2 == 1 && c3 == 0) continue;
            dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
            dp[len + 1][a][c1][c2] %= mod;
          }
        }
      }
    }
  }
  rep(c1, 4){
    rep(c2, 4){
      rep(c3, 4){
        ans += dp[n][c1][c2][c3];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
# 入力
s = input()
x, y = map(int, input().split())

C = [len(fs) for fs in s.split('T')]


# 動的計画法により、各軸について到達可能な座標の集合を求め、目標の座標に到達可能か判定
def f(cs, t):
    dp = {0}
    for c in cs:
        dp = {i + c for i in dp} | {i - c for i in dp}
    return t in dp


ans = (
    'Yes' if f(C[2::2], x - C[0]) and f(C[1::2], y) else
    'No'
)
# 出力
print(ans)


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

int ssort(int a[],int n){
    int min;
    int count=0;
    for(int i=0;i<n-1;i++){
        min=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[min])
                min=j;
            
        }
        if(i!=min){
        swap(a[min],a[i]);
        count++;
        }
    }
    
    
    return count;
}


int main (void){
    int n;
    cin>>n;
    
    int a[200];
    for(int i=0;i<n;i++)
    cin>>a[i];
    
    int count;
    count=ssort(a,n);
    
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    cout<<count<<endl;
    
}






Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n;
    priority_queue<ll> d;
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        d.push(temp);
    }
    cin >> m;
    vector<ll> t(m);
    for (ll i = 0; i < m; i++)
    {
        cin >> t[i];
    }
    if (n < m)
    {
        cout << "NO" << endl;
        exit(0);
    }
    sort(ALL(t), greater<ll>());
    for (auto e : t)
    {
        while (!d.empty() && e < d.top())
        {
            d.pop();
        }
        if (!d.empty() && e == d.top())
        {
            d.pop();
        }
        else
        {
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 3440
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        long K = sc.nextLong();
        if (K % 2 == 0) {
            out.println(A-B);
        } else {
            out.println(B-A);
        }
        out.flush();
    }
}

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

Measured memory_bytes: 21332
sx, sy, tx, ty = map(int, input().split())
ans = ""
for _ in range(ty-sy):
    ans += "U"
for _ in range(tx-sx):
    ans += "R"
for _ in range(ty-sy):
    ans += "D"
for _ in range(tx-sx):
    ans += "L"

ans += "L"

for _ in range(ty-sy+1):
    ans += "U"
for _ in range(tx-sx+1):
    ans += "R"

ans += "D"
ans += "R"

for _ in range(ty-sy+1):
    ans += "D"
for _ in range(tx-sx+1):
    ans += "L"

ans += "U"

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
int s[10001];
int finds(int n)
{
    if(s[n]==n)
        return n;
    else return s[n]=finds(s[n]);
}
int unionh(int a,int b)
{
    a=finds(a); b=finds(b);
    s[a]=b;
}

int main()
{
    for(int i=0; i<=10000; i++) s[i]=i;
    int n,q,op,x,y;
    scanf("%d%d",&n,&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d%d",&op,&x,&y);
        if(op==0) unionh(x,y);
        else{
            if(finds(x)==finds(y)) printf("1\n");
            else printf("0\n");
        }
    }
}

Measured memory_bytes: 1168
def main():
   a,b,c,d=map(int,input().split())
   p1=a*c
   p2=a*d
   p3=b*c
   p4=b*d
   x=max(p1,p2)
   y=max(p3,p4)
   print(max(x,y))

main()
        

Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		if ((s.charAt(2) == s.charAt(3)) && (s.charAt(4) == s.charAt(5))){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}


	}
}

Measured memory_bytes: 21972
import math
n = int(input())
arr = list(map(int, input().split())) 
r = float("inf")
for i  in range(n):
    r0 = 0
    while (arr[i] % 2) < 1:
        arr[i] /= 2
        r0 += 1
    if r > r0:
        r = r0

print(r)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vi is_prime(10001,true);
	is_prime[0]=is_prime[1]=false;
	repi(i,2,is_prime.size()){
		if(is_prime[i])
			for(int j=i+i;j<is_prime.size();j+=i)
				is_prime[j]=false;
	}
	vi primes;
	rep(i,is_prime.size())
		if(is_prime[i])
			primes.push_back(i);
	for(int n;cin>>n,n;){
		int i=primes.size()-1;
		while(n<primes[i] || primes[i]-primes[i-1]!=2)
			i--;
		cout<<primes[i-1]<<" "<<primes[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 956
#pragma warning(disable:4996)
#include<stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	while (1) {
		int n;
		int a[1001];

		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		sort(a, a + n);
		int b[1000];
		for (int i = 0; i < n - 1; i++) {
			if (a[i + 1] > a[i]) b[i] = a[i + 1] - a[i];
			else b[i] = a[i] - a[i + 1];
		}
		int min = 10000000;
		for (int i = 0; i < n - 1; i++) {
			if (min > b[i]) min = b[i];
		}
		printf("%d\n", min);
	}
}


Measured memory_bytes: 2772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fr(i, a, b) for (int i = a; i < b; i++)
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    int n;cin>>n;
    int h[n+1];
    fr(i,1,n+1) cin>>h[i];
    int dp[n+1];
    dp[1]=0;
    fr(i,2,n+1){
        int one = abs(h[i]-h[i-1])+dp[i-1];
        int two = (i==2) ? INT_MAX : abs(h[i]-h[i-2])+dp[i-2];
        dp[i] = min(one,two);
    }
    cout<<dp[n]<<endl;

}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define _parr(a, n) for(int __i = 0; __i < (int )n; __i++) cout << a[__i] << ' '; cout << '\n'
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).begin(), (c).end()
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define prin(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define mp make_pair
#define F first
#define S second
#define pb push_back

typedef long long int LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair< int, int> ii;
typedef vector< int> vi;

const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 2e5 + 22;
const double eps = 1e-10;

int n, m;

void _solve() {
    string x, y;
    cin >> x >> y;
    int cnt = 0;
    fr(i, 0, 3) if(x[i] == y[i]) cnt++;
    cout << cnt;
}
int main() {
    fastio;
    //t_times
    _solve();
    return 0;
}



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

int node(int y, int x) {
  return 5 * y + x;
}

int to(int dy, int dx, int now) {
  int y = now / 5 + dy, x = now % 5 + dx;
  return node(y, x);
}

bool inside(int now) {
  int y = now / 5, x = now % 5;
  return 0 <= node(y, x) && node(y, x) < 25;
}

bool g[25][25];

int main() {
  // input
  for (int i = 0; i < 9; ++i) {
    if (i & 1) {
      for (int j = 0; j < 5; ++j) {
        int f;
        scanf("%1d", &f);
        g[node(i / 2, j)][node(i / 2 + 1, j)] = f;
        g[node(i / 2 + 1, j)][node(i / 2, j)] = f;
      }
    } else {
      for (int j = 0; j < 4; ++j) {
        int f;
        scanf("%1d", &f);
        g[node(i / 2, j)][node(i / 2, j + 1)] = f;
        g[node(i / 2, j + 1)][node(i / 2, j)] = f;
      }
    }
  }

  int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
  char d[] = {'U', 'R', 'D', 'L'};

  int now = node(0, 1);
  int direction = 1;
  string ans = "R";

  while (now) {
    direction = (direction + 3) % 4;
    for (int i = 0; i < 4; ++i) {
      int dir = (direction + i) % 4;
      int next = to(dy[dir], dx[dir], now);
      if (!inside(next) || !g[now][next]) continue;

      now = next;
      direction = dir;
      ans += d[dir];
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int n, m;
  string a, b, c;
  while(true){
    cin>>a;
    if(a=="-"){
      break;
    }
    cin>>n;
    for(int i=0; i<n; ++i){
      cin>>m;
      b = a.substr(0, m);
      c = a.substr(m);
      a = c + b;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 3152
N=int(input())
A=list(map(int,input().split()))
ls=[0,0,0]
cnt=1
for i in range(N):
  c=0
  flag=False
  for j in range(3):
    if A[i]==ls[j]:
      c+=1
      if flag==False:
        ls[j]+=1
        flag=True
  cnt=cnt*c
print(cnt%1000000007)

Measured memory_bytes: 52952
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.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 EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}


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

    int N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll w = 0, h = 0;
    int cnt = 1;
    REP(i,N-1) {
        if (a[i] != a[i+1]) {
            cnt = 1;
        } else {
            cnt++;
        }

        if (cnt>=2 && w==0) {
            w = a[i];
            cnt -= 2;
        }
        if (cnt>=2 && h==0) {
            h = a[i];
            break;
        }
    }

    ll ans = w * h;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
/* 
 * Project: AtCoder Beginners Contest 150 A - 500 Yen Coins
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/20
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
using namespace std;

int k, x;

void solve() {

    if (500 * k >= x)
        printf("Yes\n");
    else
        printf("No\n");
}

int main() {

    scanf("%d", &k);
    scanf("%d", &x);

    solve();

}

Measured memory_bytes: 3160
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
const int N = 1e5+2;
signed main()
{
    fast;
    string s,t;
    cin>>s>>t;
    int l = t.size();
    int n = s.size();
    bool flag = 0;
    string ans ="";
    ans.pb((char)123);
    for(int i=0;i<=n-l;i++)
    {
        int temp = 1;
        string str = s;
        for(int j=0;j<l;j++)
        {
            if(s[i+j]!=t[j] && s[i+j]!='?')
            {
                temp = 0;
                break;
            }
            str[i+j] = t[j];
        }
        if(temp)
        {
            flag = 1;
            replace(all(str),'?','a');
            ans = min(ans,str);
        }   
    }
    if(flag)
        cout<<ans;
    else cout<<"UNRESTORABLE";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k,mod=1e9+7;
ll sm[109][100009],dp[109][100009],a[100009];
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<=a[0];i++)
    {
        dp[0][i]=1;
    }
    sm[0][0]=1;
    for(int i=1;i<=k;i++)
    {
        sm[0][i]=dp[0][i]+sm[0][i-1];
        sm[0][i]%=mod;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(j==0)
            {
                sm[i][0]=1;
                dp[i][0]=1;continue;
            }
            dp[i][j]=sm[i-1][j];
            if(j-a[i]>0)dp[i][j]-=sm[i-1][j-a[i]-1];
            dp[i][j]+=mod;
            dp[i][j]%=mod;
            sm[i][j]=(dp[i][j]+sm[i][j-1])%mod;
        }
    }
    cout<<dp[n-1][k];
}


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

int main() {

    long long int i,a[200005]={0},t,x,p=0,n;
    
    cin>>t;
    n=t;
    
    while(t--){
        
        cin>>x;
        
        if(x-1==p){
            a[p]=x;
            p++;
        }
        
    }
    // cout<<p;
    if(p==0)
    {
        cout<<"-1";
    }
    else{
        cout<<n-p;
    }
    
	return 0;
}


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

int h[100005];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        h[a]++;
        h[b + 1]--;
    }
    for (int i = 0; i < 100005; i++) h[i + 1] += h[i];
    int ans = 0;
    for (int i = 0; i < 100005; i++) {
        if (i <= h[i] + 1) {
            ans = max(ans, i - 1);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector <vector<int>> vec;
vector <int> dp;
vector <int> vis;

void dfs(int i){
    //cout<<i<<endl;
    if(vec[i].size()==0){dp[i]=0;vis[i]=2;}
    vis[i]=1;
    for(auto v:vec[i]){
        if(dp[v]==-1)dfs(v);
        dp[i]=max(dp[v]+1,dp[i]);
    }
    vis[i]=2;
}

int main() {
    int n,m;
    cin>>n>>m;
    vec.assign(n,vector <int>(0));
    dp.assign(n,-1);
    vis.assign(n,0);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        vec[a].pb(b);
    }
    int mx=-1;
    for(int i=0;i<n;i++){
    if(vis[i]==0)dfs(i);
    mx=max(mx,dp[i]);}
    cout<<mx<<endl;
    
    
}

Measured memory_bytes: 8576
H,W,K = map(int,input().split())
mod = 10**9+7
dp = W*[0]
dp[0] = 1
fib = [1,1,2,3,5,8,13,21,34,55,89]

for h in range(H):
  t = W*[0]
  for w in range(W):
    if 0<w:
      t[w]+=dp[w-1]*fib[w-1]*fib[W-w-1]
    t[w]+=dp[w]*fib[w]*fib[W-w-1]
    
    if w<W-1:
      t[w]+=dp[w+1]*fib[w]*fib[W-w-2]
    t[w]%=mod
  dp = t

print(dp[K-1])

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

using namespace std;

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int t = 1;
	// cin >> t;
	while (t--) { 
		solve();
	}
	return 0;
}
int s[50];
char c[50];
int n, m;
void solve() {
	cin >> n >> m;
	rep(i, 0, m) {
		cin >> s[i] >> c[i];
		s[i]--;
	}
	rep(i, 0, 1000) {
		bool ok = true;
		string str = to_string(i);
		if ((int) str.size() != n)
			ok = false;
		if (!ok)
			continue;
		rep(j, 0, m) {
			if (str[s[j]] != c[j])
				ok = false;
		}
		if (ok) {
			cout << i;
			return;
		}
	}
	cout << -1;
}	
	

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

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

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,x;
	while(scanf("%d",&n),n)
	{
		int a[10]={0};
		while(n--)scanf("%d",&x),++a[x];
		for(n=0;n<10;++n)
		{
			if(a[n])while(a[n]--)putchar('*');
			else putchar('-');
			puts("");
		}
	}
	return 0;
}

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

int main() { /* ここに書く */
  
  int N , P , Min , Ans , i ;
  cin >> N ;
  Min = 200000 ;
  Ans = 0 ;
  i = 0 ;
  
  while( i < N ){
    cin >> P ;
    if( Min >= P ){
      Ans++ ;
      Min = P ;
      i++ ;
    }
    else{
      i++ ;
    }
  }
  cout << Ans << endl;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    int res = INF;
    rep(t,n+1){
        int sumA = 0, sumB = 0;
        rep(i,n){
            if (i < t) sumA += w[i];
            else sumB += w[i];
        }
        res = min(res, abs(sumA - sumB));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>

using namespace std;
using experimental::any;

#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define MODE 1
#define DEB(X) if(MODE)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(MODE)cout<<X<<" ";
#define ARDEB(i,X) if(MODE)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) if(MODE){(f)? cout<<"true ":cout<<"false ";}
#define FORDEB(n,X) if(MODE)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(MODE)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
struct P2{int x,y;};
//struct edge{int from,cost,to;};
#define Endl endl

const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000;

int main(){
	int n,a[300],ans;
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	for(int i=0;;i++){
		int dim=0;
		for(int j=0;j<n;j++){
			if(a[j]%2==0){
				dim++;
				a[j]/=2;
			}
		}
		if(dim!=n){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
class Dice {
public:
	int top, bottom, west, east, south, north;
	Dice(){
		top = 1;bottom = 6;
		west = 4;east = 3; 
		south = 2;north = 5;
	}
	void North(){
		int tmp = top;
		top = south;
		south = bottom;
		bottom = north;
		north = tmp;
		return;
	}
	void East(){
		int tmp = top;
		top = west;
		west = bottom;
		bottom = east;
		east = tmp;
		return;
	}
	void West(){
		int tmp = top;
		top = east;
		east = bottom;
		bottom = west;
		west = tmp;
		return;
	}
	void South(){
		int tmp = top;
		top = north;
		north = bottom;
		bottom = south;
		south = tmp;
		return;
	}
	void Right(){
		int tmp = south;
		south = east;
		east = north;
		north = west;
		west = tmp;
		return;
	}
	void Left(){
		int tmp = south;
		south = west;
		west = north;
		north = east;
		east = tmp;
		return;
	}
};

int main(){
	int n;
	while(cin>>n, n){
		long long total = 1;
		Dice d;
		for(int i = 0; i < n; i++){
			string s;
			cin>>s;
			if(!s.compare("North"))
				d.North();
			else if(!s.compare("East"))
				d.East();
			else if(!s.compare("West"))
				d.West();
			else if(!s.compare("South"))
				d.South();
			else if(!s.compare("Right"))
				d.Right();
			else if(!s.compare("Left"))
				d.Left();
			total += d.top;
		}
		cout<<total<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

bool solve(string s, string t)
{
    int n = s.size();
    vector<char> v(128, '?');
    for(int i=0; i<n; ++i){
        if(v[s[i]] == '?' || v[s[i]] == t[i])
            v[s[i]] = t[i];
        else
            return false;
    }
    return true;
}

int main()
{
    string s, t;
    cin >> s >> t;

    if(solve(s, t) && solve(t, s))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 1544
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
string s;
cin>>s;
int n=s.size();
sort(all(s));
s.erase(unique(all(s)),s.end());
if(n==s.size())cout<<"yes"<<endl;
else cout<<"no"<<endl;
}

Measured memory_bytes: 256
# (10-x) ways: (0,x)-(9-x,9) -> (x, -x)           <- This should never happens when D > 0
# (x) ways:    (10-x,0)-(9,x-1) -> (x-10, 10 - x)

def solve(d, k, outer):
  if k <= 1:
    return 10**k if d == 0 else 0
  # if d >= 10**k:
  #   return 0

  t = (-d)%10 # 10-d%10 doesn't work when d = 10
  d -= t*10**(k-1) - t
  return (10-t-outer)*solve(abs(d//10), k-2, 0)

D = int(input())
result = 0
for k in range(1,20):
  result += solve(D, k, 1)

print(result)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main()
{
  char S1[]="ARC";
  char S2[]="ABC";
  char S[4];
  
  scanf("%s",S);
  if(strcmp(S,S1))
    printf("%s",S1);
  else
    printf("%s",S2);
  return 0;
}

Measured memory_bytes: 1728
fun main(array: Array<String>) = abc112c()

fun abc112c() {
    data class Coordinate(val x: Long, val y: Long, val h: Long) {
        override fun toString() = "$x $y $h"
    }

    val n = readLine()!!.toInt()
    val coordinates = Array(n) {
        val (x, y, h) = readLine()!!.split(' ').map { it.toLong() }
        Coordinate(x, y, h)
    }.filter { it.h > 0 }

    if (coordinates.size == 1) return println(coordinates.first())

    val answer = (0..100L).map { y ->
        (0..100L).map { x ->
            coordinates.map { it.h + Math.abs(x - it.x) + Math.abs(y - it.y) }.distinct()
                .let { if (it.size == 1) Coordinate(x, y, it.first()) else null }
        }
    }.flatten().filterNotNull().firstOrNull() ?: error("なんで？")

    println(answer)
}


Measured memory_bytes: 54508
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	string s;
	cin>>s;
	string a;
	for(int i=0; i<s.size(); i++){
		if(i%2==0) a += s[i];
	}
	cout<<a;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	S[0]='2';
	S[1]='0';
	S[2]='1';
	S[3]='8';
	cout<<S<<endl;
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a, b;
  cin >> a >> b;

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


Measured memory_bytes: 256