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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, x, y;
    cin >> H >> W >> x >> y;
    double s = H * W * 0.5;

    cout << OF64 << s << " ";
    if (x * 2 == H && y * 2 == W)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

int main() {
	ll x, y;
	cin >> x >> y;
	if (x % y == 0) cout << -1 << endl;
	else cout << x << endl;
	return 0;
}

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

using namespace std;

int seq[19];
int N;

long long dfs(int l,int r,long long lt,long long rt)
{
	if(l + 1 == r) return 0;
	long long ans = 1e18;
	long long tms = lt + rt;
	for(int i = l + 1;i < r; ++ i) ans = min(ans,dfs(l,i,lt,tms) + dfs(i,r,tms,rt) + tms * seq[i]);
	return ans;
}

int main()
{
	scanf("%d",&N);
	for(int i = 1;i <= N; ++ i) scanf("%d",&seq[i]);
	printf("%lld\n",dfs(1,N,1,1) + seq[1] + seq[N]);
}

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

using namespace std;

const int MOD = 1e9+7;

using ll = long long;

int addm(int a, int b) {
	return ((ll)a+b)%MOD;
}

int mulm(int a, int b) {
	return ((ll)a*b)%MOD;
}

int main() {
	int n;
  	cin >> n;
  	vector<int> arr(n), pref(n);
  	for(auto &x:arr) cin >> x;
  	pref[0] = arr[0];
  	for(int i = 1; i < n; i++) {
    	pref[i] = addm(pref[i-1], arr[i]);
    }
  	int sum = 0;
  	for(int i = 1; i < n; i++) {
    	sum = addm(sum, mulm(pref[i-1], arr[i]));
    }
  	cout << sum;
}


Measured memory_bytes: 4812
#include<iostream>
#include<vector>
#include<queue>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
  int h, w;
  while(cin >> w >> h && h != 0){
    vector< vector<char> > L(h);
    vector< vector<char> > R(h);
    pair<int, int> ls;
    pair<int, int> rs;
    char a;
    for(int i = 0; i < h ; i++){
      for(int j = 0; j < w ; j++){
        cin >> a;
        L[i].push_back(a);
        if(a == 'L') ls = make_pair(i, j);
      }
      for(int j = 0; j < w ; j++){
        cin >> a;
        R[i].push_back(a);
        if(a == 'R') rs = make_pair(i, j);
      }
    }

    int flag = 0;
    vector< pair<int, int> > move;
    move.push_back(make_pair(0,1));
    move.push_back(make_pair(1,0));
    move.push_back(make_pair(0,-1));
    move.push_back(make_pair(-1,0));
    int nodes[50][50][50][50] = {{{{0}}}};
    nodes[ls.first][ls.second][rs.first][rs.second] = 1;
    queue< pair< pair<int, int> , pair<int, int> > > q;
    q.push(make_pair(ls, rs));
    while(!q.empty()){
      pair<pair<int, int>, pair<int, int> > k = q.front();
      q.pop();
      int lv = k.first.first;
      int lh = k.first.second;
      int rv = k.second.first;
      int rh = k.second.second;
      for(int i = 0; i < 4; i++){
        pair<int, int> m = move[i];
        int mv = m.first;
        int mh = m.second;
        int a,b,c,d;
        if(lv + mv >= 0 && lv + mv < h) a = lv + mv;
        else a = lv;
        if(lh + mh >= 0 && lh + mh < w) b = lh + mh;
        else b = lh;
        if(rv + mv >= 0 && rv + mv < h) c = rv + mv;
        else c = rv;
        if(rh - mh >= 0 && rh - mh < w) d = rh - mh;
        else d = rh;
        if(L[a][b] == '%' && R[c][d] == '%') flag = 1;
        else if(L[a][b] == '%' || R[c][d] == '%') continue;
        if(L[a][b] == '#'){
          a = lv;
          b = lh;
        }
        if(R[c][d] == '#'){
          c = rv;
          d = rh;
        }
        if(nodes[a][b][c][d] != 1){
          q.push(make_pair(make_pair(a,b), make_pair(c,d)));
          nodes[a][b][c][d] = 1;
        }
      }
    }
    if(flag == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}



Measured memory_bytes: 28356
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll N,W;cin>>N>>W;
  vl w(N),v(N);
  rep(i,N){
    cin>>w[i]>>v[i];
  }
  vvl dp(101,vl(100001));
  rep(i,100001){
    rep(j,N){
      dp[j][i]=1000000001;
    }
  }
  rep(i,100001){
    dp[0][i]=1000000001;
  }
  
  dp[0][0]=0;
  
  rep(i,N){
    for(ll j=0;j<=100000;j++){
      if(j<v[i]){
        dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      }
      else dp[i+1][j]=min(dp[i][j-v[i]]+w[i],dp[i][j]);
    }
  }
  int ans =0;
  rep(i,100001){
    if(dp[N][i]<=W)ans=i;
  }
  cout<<ans<<endl;
}





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

int main() {
  char b;
  cin >> b;
  if(b == 'A') {
    b = 'T';
  }
  else if(b == 'T') {
    b = 'A';
  }
  else if(b == 'C') {
    b = 'G';
  }
  else if(b == 'G') {
    b = 'C';
  }  
  cout << b << endl;
}


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

h = 2 * math.pi * H / 12 + math.pi / 6 * M / 60
m = 2 * math.pi * M / 60

ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(h - m))
print(ans)

Measured memory_bytes: 9428
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
 
    char ch = sc.nextChar();
    if('A' <= ch && ch <= 'Z'){
      System.out.println('A');
    }else{
      System.out.println('a');      
    }
 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 25348
#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[i];
    }
    int cnt = 0;
    bool zero = false;
    for (int i = 0; i < N; i++)
    {
        if (A[i] < 0)
        {
            cnt += 1;
        }
        if (A[i] == 0)
        {
            zero = true;
        }
    }
    for (int i = 0; i < N; i++)
    {
        A[i] = abs(A[i]);
    }
    sort(A.begin(), A.end());
    int minA = A[0];
    long long sumA = accumulate(A.begin(), A.end(), 0LL);
    if (cnt % 2 == 0 || zero)
    {
        cout << sumA << endl;
    }
    else
    {
        cout << sumA - 2 * minA << endl;
    }
}

Measured memory_bytes: 640
#!/usr/bin/env php
<?php
// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
function solve(string $S)
{
    $z = 0;
    $o = 0;
    $toggle = true;
    for($i = 0; $i < strlen($S); $i++) {
        $v = (int)($S[$i]);
        if ($toggle) {
            if ($v) {
                $z++;
            } else {
                $o++;
            }
        } else {
            if ($v) {
                $o++;
            } else {
                $z++;
            }
        }
        $toggle = !$toggle;
    }
    echo min($o, $z).PHP_EOL;
}

fscanf(STDIN, '%s', $S);
solve($S);



Measured memory_bytes: 4728
N, M = gets.split.map(&:to_i)
ab_list = N.times.map { gets.split.map(&:to_i) }.sort_by { |(a, b)| a }
yen = 0
rest = M
ab_list.each do |(a, b)|
  c = [b, rest].min
  yen += a * c
  rest -= c
  break if rest == 0
end
puts yen


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

long ctoi(char x)
{
  switch (x) {
  case '0': return 0;
  case '1': return 1;
  case '2': return 2;
  case '3': return 3;
  case '4': return 4;
  case '5': return 5;
  case '6': return 6;
  case '7': return 7;
  case '8': return 8;
  case '9': return 9;
  default: return 0;
  }
}

long arr[16];// = {0};

long lpow(int x, int i)
{
  long ans = 1;
  for (int j = 0; j < i; j++) { ans *= x; }
  return ans;
}
long get_sum(int j, int len)
{
  long ans = 0;
  int cnt = 1;
  int i;
  for (i = 0; i < len; i++) {
    if (j & (1<<i)) {
      ans += arr[i]*lpow(10,cnt-1);
      cnt = 1;
    }
    else {
      ans += arr[i]*lpow(10,cnt-1);
      cnt++;
    }
  }
  ans += arr[i]*lpow(10,cnt-1);
  return ans;
}

int main()
{
  long sum = 0;

  string S;
  cin >> S;

  for (int i = S.length()-1; i >= 0; i--) arr[S.length()-1-i] = ctoi(S[i]);
  //  for (int i = 0; i < S.length(); i++) arr[i] = ctoi(S[i]);

  //  int n = S.length();
  if (S.length() == 1) { sum = arr[0]; }
  else {
    for (int i = 0; i < (1<<(S.length()-1)); i++) {
      sum += get_sum(i, S.length()-1);
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
v=list(map(int,input().split()))
vrev=v[::-1]
vab=[]
ans=0
for i in range(min(n,k)+1):
  for j in range(min(n,k)-i+1):
    vab=v[:i]+vrev[:j]
    vab.sort()
    if len(vab)>0 and vab[0]<0:
      for l in range(min(k-len(vab),len(vab))):
        if vab[l]<0:
          vab[l]=0
    ans=max(ans,sum(vab))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;


int main() {
	vector<int> a;
	a.resize(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

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

int main()
{
    int N,a[220000],key,val;
    cin >> N;
    for (int i=0; i<N; ++i)
    {
        cin >> val;
        key = i+1;
        a[key] = val;
    }

    key = 1;
    key = a[key];

    for (int i=0; i<N; ++i)
    {
        if (key == 2)
        {
            cout << i+1 << endl;
            return 0;
        }
        key = a[key];
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

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

	printf("%d\n",(N-1)*(M-1));

	return 0;
}


Measured memory_bytes: 3800
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char map[505][505];
int def[505][505];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
vector<int>to[200005];

int main() {
	int n, q;
	cin >> n >> q;
	int a, b;
	for (int i = 0; i < n-1; i++) {
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	int p, x;
	vector<ll>ans(n, 0);
	for (int j = 0; j < q; j++) {
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	
	queue<int>que;
	vector<ll>dist(n,inf);
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int id : to[v]) {
			if (dist[id] != inf)continue;
			
			dist[id] = dist[v] + 1;
			ans[id] += ans[v];
			que.push(id);
		}
	}
	
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}
	
	

Measured memory_bytes: 17908
from collections import deque
n = int(input())


def factorization(n):
    retval = []
    tmp = n
    for i in range(2, int(-(-n**.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            retval.append([i, cnt])

    if tmp != 1:
        retval.append([tmp, 1])
        # retval.append(tmp)
    # if not retval:
        # retval.append((n, 1))
    return retval


fact = factorization(n)
used = set()
m = len(fact)
ans = 0
left = []
# # iこずつとっていく
# for j in range(m):
#     fact[j][1] -= 1
#     ans += 1
#     used.add(fact[j][0])
#     left.extend([fact[j][0] for _ in range(fact[j][1])])

# print(left, used, ans)


for i in range(1, 1000):
    # iこずつとっていく
    for j in range(m):
        if i <= fact[j][1]:
            fact[j][1] -= i
            ans += 1
            used.add(fact[j][0]**i)
    # 組み合わせて、iこ取れるか確かめる
print(ans)

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

int main () {
  string s;
  cin >>s;
  int cnts,cntl;

  for (int i=0;i<s.size();i++){
    if(s.at(i) =='A'){
      cnts =i;
      break;
    }
  }
  for(int j=s.size()-1;j>0;j--){
    if(s.at(j)=='Z'){
      cntl =j;
      break;
    }
  }
  cout <<cntl-cnts+1<<endl;
}


Measured memory_bytes: 640
h,w=map(int,input().split())
p = [input() for i in range(h)]
for y in range(h):
    for x in range(w):
        j=0
        if p[y][x]=="#":
            if x>0 and p[y][x-1]=="#":j=1
            elif j==0 and y>0 and p[y-1][x]=="#":j=1
            elif j==0 and x!=w-1 and p[y][x+1]=="#":j=1
            elif j==0 and y!=h-1 and p[y+1][x]=="#":j=1
            if j==0:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
 
int main(){
    int n;
    cin >> n;
    vector<ll> a(3*n);
    rep(i, 3*n) cin >> a[i];
 
    vector<ll> v(3*n-1), u(3*n-1);
 
    ll lsum = 0;
    priority_queue<ll, vector<ll>, greater<ll>> lq;
    rep(i, n){
        lsum += a[i];
        lq.push(a[i]);
    }
    v[n-1] = lsum;
    for(int i=n; i<2*n; i++){
        ll t = lq.top();
        if(t < a[i]){
            lsum += (a[i] - t);
            lq.pop();
            lq.push(a[i]);
        }
        v[i] = lsum;
    }
 
//    rep(i, 3*n-1) cout << v[i] << ", ";
//    cout << endl;
 
    ll rsum = 0;
    priority_queue<ll> rq;
    reverse(all(a));
    rep(i, n){
        rsum += a[i];
        rq.push(a[i]);
    }
    u[n-1] = rsum;
    for(int i=n; i<2*n; i++){
        ll t = rq.top();
        if(t > a[i]){
            rsum += (a[i] - t);
            rq.pop();
            rq.push(a[i]);
        }
        u[i] = rsum;
    }
    reverse(all(u));
 
//    rep(i, 3*n-1) cout << u[i] << ", ";
//    cout << endl;
 
    ll ans = - 1e18;
    for(int i=n-1; i<2*n; i++){
        chmax(ans, v[i]-u[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9588
from collections import deque
import sys
read = sys.stdin.readline

s = deque(read().rstrip())
q = int(read())

rev = 0
for _ in range(q):
    a = tuple(read().split())
    if a[0] == '1':
        rev ^= 1
    else:
        dir = rev ^ int(a[1]) - 1
        if dir == 0:
            s.appendleft(a[2])
        else:
            s.append(a[2])

if rev:
    print(''.join(s)[::-1])
else:
    print(''.join(s))


Measured memory_bytes: 14192
function main(input) {
  const lines = input.trim().split("\n");
  const K = +lines[0];
  const [A, B] = lines[1].split(' ').map(Number);

  let res = 'NG';
  let d, i = 1;
  while (d = K * i, d <= B) {
    if (d >= A) {
      res = 'OK';
      break;
    }
    i++;
  }

  console.log(res);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    ll N, K; cin>>N>>K;
    ll ans=0;
    if(N<=K){
        ans=min(N,K-N);
    }
    else{
        ans=min(N%K, K-N%K);
    }
    cout << ans << endl;
}

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

public class  Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String sp;
        int n = Integer.parseInt(br.readLine());
       for (int i = 0; i < n; i++) {
            sp = br.readLine();
            if (sp.startsWith("insert")) {
                list.addFirst(sp.substring(sp.indexOf(" ") + 1));
            }else if (sp.equals("deleteFirst")) {
                list.removeFirst();
            } else if (sp.equals("deleteLast")) {
                list.removeLast();
            } else if (sp.startsWith("delete")) {
                list.remove(sp.substring(sp.indexOf(" ") + 1));
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder ans = new StringBuilder();
        ans.append(list.poll());
        for (String s : list) {
            ans.append(" ");
            ans.append(s);
        }
        bw.write(ans.toString());
        bw.newLine();
        bw.close();
        br.close();
    }
}



Measured memory_bytes: 160020
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Jun  6 18:50:20 2018
//
package main

import "fmt"

var N, M int

var graph [][]int
var path []int
var visited []bool

func remove(v, w int) {
	for i, x := range graph[v] {
		if w == x {
			graph[v] = append(graph[v][:i], graph[v][i+1:]...)
		}
	}
}

func reverse(path []int) {
	for i, j := 0, len(path)-1; i < j; i, j = i+1, j-1 {
		path[i], path[j] = path[j], path[i]
	}
}

func extend() {
	for {
		edge := path[len(path)-1]
		appended := false
		for _, n := range graph[edge] {
			if !visited[n] {
				visited[n] = true
				path = append(path, n)
				remove(edge, n)
				remove(n, edge)
				appended = true
				break
			}
		}

		if !appended {
			return
		}
	}
}

func main() {
	fmt.Scan(&N, &M)

	graph = make([][]int, N+1)
	for i := range graph {
		graph[i] = make([]int, 0)
	}

	for i := 0; i < M; i++ {
		var A, B int
		fmt.Scan(&A, &B)
		graph[A] = append(graph[A], B)
		graph[B] = append(graph[B], A)
	}

	next := graph[1][0]
	path = []int{1, next}
	visited = make([]bool, N+1)
	visited[1], visited[next] = true, true

	extend()
	reverse(path)
	extend()

	fmt.Println(len(path))
	for i, v := range path {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(v)
	}
	fmt.Println()
}


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

using namespace std;

#define lli long long unsigned int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0

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

lli lcm(lli a,lli b){
	return a/gcd(a,b)*b;
}


int main(){

	lli n;
	vector<lli> t;
	cin>>n;
	t.resize(n);
	REP(i,n)cin>>t[i];

	lli ans = t[0];
	for(lli i=1;i<n;i++){
		if(ans>=t[i])ans = lcm(ans,t[i]);
		else ans = lcm(t[i],ans);
	}

	cout<<ans<<endl;

	return 0;
}

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

using namespace std;

int main(){

    int n;

    string s;

    cin >> n;
    cin >> s;

    int m=0,q=0;

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                int r=0;
                int p=0;
                for(int l=0;l<n-2;l++){
                    if(s[l]-'0'==i){
                        p=l;
                        r+=1;
                        break;
                    }
                    else if(l==n-3) p=n;
                }
                if(p<n){
                    for(int o=p+1;o<n-1;o++){
                        if(s[o]-'0'==j){
                            p=o;
                            r+=1;
                            break;
                        }
                        else if(o==n-2) p=n;
                    }
                }
                if(p<n){
                    for(int u=p+1;u<n;u++){
                        if(s[u]-'0'==k){
                           r+=1;
                            break;
                        }
                    }
                }
                if(r==3)m+=1;
                
               
                
            }
        }
    }

    cout << m << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

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

typedef pair<int, int> P;

void solve(int no) {
	char field[8][8];
	for (int i = 0; i < 8; i++)
		for (int j = 0; j < 8; j++)
			cin >> field[i][j];

	int x, y;
	queue<P> que;
	cin >> x >> y;
	que.push(P(x - 1, y - 1));

	while (!que.empty()) {
		P p = que.front(); que.pop();
		field[p.second][p.first] = '0';
		for (int i = 0; i < 4; i++) {
			for (int j = 1; j <= 3; j++) {
				int nx = p.first + (dx[i] * j);
				int ny = p.second + (dy[i] * j);
				if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
					if (field[ny][nx] == '1')
						que.push(P(nx, ny));
					field[ny][nx] = '0';
				}
			}
		}
	}

	printf("Data %d:\n", no);
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++)
			cout << field[i][j];
		cout << endl;
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		solve(i + 1);
	}
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool visited[n] = {};
    vector<ll> path0, path1;
    visited[0] = true;
    path0.push_back(0);
    ll now = 0;
    while (true) {
        bool flag = false;
        for (ll next : g[now]) {
            if (visited[next]) {
                continue;
            }
            flag = true;
            path0.push_back(next);
            visited[next] = true;
            now = next;
            break;
        }
        if (!flag) {
            break;
        }
    }

    path1.push_back(0);
    now = 0;
    while (true) {
        bool flag = false;
        for (ll next : g[now]) {
            if (visited[next]) {
                continue;
            }
            flag = true;
            path1.push_back(next);
            visited[next] = true;
            now = next;
            break;
        }
        if (!flag) {
            break;
        }
    }

    if (path1.size() == 1) {
        ll len = path0.size();
        cout << len << endl;
        rep(i, len) { cout << path0[i] + 1 << " "; }
        cout << endl;
    } else {
        ll len0 = path0.size(), len1 = path1.size();
        cout << len0 + len1 - 1 << endl;
        repb(i, len1) { cout << path1[i] + 1 << " "; }
        repd(i, 1, len0) { cout << path0[i] + 1 << " "; }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 9692
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int cnt = 0;
        for (int j = 1; j*j <= i; j++) {
	  if (i%j == 0) {
	    cnt++;
            if (j*j != i) {
                cnt++;
            }
	  }
        }
        if (cnt == 8) {
            ans++;
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,k;
string s,t;

int main() {
  cin >> n >> k;
  int a; map<int,int> mp;
  rep(i,n){
   cin >> a; mp[a]++;
  }
  vector<int> v;
  for(auto m :mp) v.push_back(m.second);
  sort(all(v));
  int ans=0,cnt=mp.size();
  for(int i=0;i<v.size();i++){
    if(cnt<=k) break;
    ans+=v[i], cnt--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 10748
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  n <- (read::String -> Int) <$> getLine
  arr1 <- array (1, n + 1) . zip [1..(n + 1)] . map (read::String -> Int) . words <$> getLine
  arr2 <- array (1, n) . zip [1..n] . map (read::String -> Int) . words <$> getLine
  print $ sum $ foldl (
    \(x:xs) i -> if arr2 ! i > (arr1 ! i) - x 
      then (min (arr1 ! (i + 1)) ((arr2 ! i) - (arr1 ! i) + x)):(arr1 ! i):xs 
      else 0:((arr2 ! i) + x):xs
    ) [0] [1..n]


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

using namespace std;

int main()

{
    int n,k,sum=0;
    cin>>n>>k;
    int p[n],i;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
    }
    sort(p,p+n);
    for(i=0;i<k;i++)
    {
        sum+=p[i];
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
  cin>>S;
  for(int i=0;i<S.size();i++){
    if(S[i]==',') S[i]=' ';
  }
  cout<<S<<endl;
    return 0;
}


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */


vi primefact(int n){
 
    vi ret;
    int t = n;
 
    rep(i,2,sqrt(t + 10)){
        if(n % i == 0){
            while(n % i == 0){
                ret.push_back(i);
                n /= i;
            }
        }
    }
    if(n > 1) ret.push_back(n);
    sort(all(ret));
 
    return ret;
 
}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, p; cin >> n >> p;
    if(n == 1){
        print(p);
        return 0;
    }

    if(n > 40){
        print(1);
        return 0;
    }



    vi pf = primefact(p);

    map<int, int> mp;



    rep(i,0,pf.size()){
        mp[pf[i]]++;
    }





    int ans = 1;

    each(mp, itr){
        if(itr -> second < n) continue;
        ans *= pow(itr -> first, ((itr -> second) / n));
    }



    print(ans);




   


    

    

   

    




    



    





    


    

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll A,B,C;
  cin>>A>>B>>C;
  if(A<=C&&C<=B) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(a, b);
    while (a) {
        a++; b++;
        vvi dp(a, vi(b, 0));
        Rep(i, a) {
            string st;
            cin >> st;
            rep(j, st.size()) {
                if (st[j] == '*') {
                    dp[i][j+1]++;
                }
            }
        }
        Rep(i, a) {
            Rep(j, b) {
                dp[i][j] += dp[i][j-1];
            }
        }
        Rep(j, b) {
            Rep(i, a) {
                dp[i][j] += dp[i-1][j];
            }
        }
   //     rep(i, a) {rep(j, b) {cout << dp[i][j] << " "; } cout << endl;}

        int ans = 0;
/*
    int ans = -INF;
    Rep(i, n) {
        Rep(j, n) {
            rep(k, i+1) {
                rep(l, j+1) {
                    int tmp = -INF;
                    if (i == k && j == l) {
                        continue;
                    } else if (i == k || j == l) {
                        tmp = data[i][j] - data[k][l];
                    } else {
                        tmp = data[i][j] - data[k][j]
                            - data[i][l] + data[k][l];
                    }
                    ans = max(ans, tmp);
                }
            }
        }
    }
*/
        Rep(st, a) {
            rep(sz, (a-st)) {
  //              cout << "(" << st << " , " << sz << ")" << endl;
                int l = 1, r = 1;
                while (r < b) {
                    int tmp = 0;
                    tmp = dp[st+sz][r] - dp[st+sz][l-1] - dp[st-1][r]
                        + dp[st-1][l-1];
                    while (r < b && !tmp) {
                        ans = max(ans, ((r - l + 1) * (sz+1)));
                        r++;
                        tmp = dp[st+sz][r] - dp[st+sz][l-1]
                            - dp[st-1][r] + dp[st-1][l-1];
                    }
 //                   cout << "(" << st << "," << l << ")";
//                    cout << "(" << st+sz << "," << r << ")" << " ";
                   // ans = max(ans, ((r - l) * (sz+1)));
                    l = ++r;
                    //r++;
                }
   //             cout << endl;
            }
        }

        cout << ans << endl;
        cin >> a >> b;
    }

    return 0;
}

Measured memory_bytes: 5032
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    int n=in.nextInt(),k=in.nextInt();
    String s=in.next();
    String p="";
    for(int i=0;i<n;i++){
      if(i==k-1)
      p+=Character.toLowerCase(s.charAt(i));
      else
      p+=s.charAt(i);
    }
    System.out.println(p);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,m;
 	cin >> n>>m;
 	cout << m-n+m << endl;
 }

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt)
    println((an.map { countTwoNum(it) }).min())
}

fun countTwoNum(num: Int): Int {
    var twoNum = 0
    var temp = num
    while (temp % 2 == 0) {
        twoNum++
        temp /= 2
    }
    return twoNum
}



Measured memory_bytes: 36076
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
if A >= K:
    ans = K
elif (A+B) >= K:
    ans = A
else:
    ans = A - 1*(K-(A+B))

print(ans)


Measured memory_bytes: 77256
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()

import math

def sieve_of_eratosthenes(n):
    prime_list = []  # n以下の素数のリスト
    A = [1]*(n+1)    # A[i] = iが素数なら1,その他は0
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list

primelist = sieve_of_eratosthenes(N)

list = [i for i in range(N+1)]

for p in primelist:
    a = p
    r = 2
    while a <= N:
        for i in range(1,N//a+1):
            if i % p == 0:
                continue
            else:
                list[a*i] *= r
        a *= p
        r += 1

print(sum(list))

Measured memory_bytes: 251168
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 1;
    char[] ca = sc.next().toCharArray();
    for (int i = 0; i < n - 1; i++)
      if (ca[i] != ca[i + 1])
        count++;
    System.out.println(count);
  }
}


Measured memory_bytes: 26708
#include <iostream>
#include <string>
#include <algorithm>
#include  <set>
#include <cmath>
using namespace std;
typedef long long ll;


int main() {
	int a, b, c, d, e, f, g, h,i,j,n,m,l,sum=0;
	int z[10],k[10],s[10][10],p[10];

	ll  aa, bb;

	cin >> n >> m;
	a = n;
	for (i = 0; i < m; i++) {
		cin >> k[i];

		for (j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	
	}
	for (i = 0; i < m; i++) cin >> p[i];



	for (i = 0; i < pow(2, a); i++) {
		b = i;
		
		
		for (j = 0; j < a; j++) {


			if (b >= pow(2, a - 1 - j)) {
				z[j] = 1;

				b = b - pow(2, a - 1 - j);
			}
			else z[j] = 0;
		}
		e = 0;
		do {

			h = 0;
			for (f = 0; f < k[e]; f++) {
				g = s[e][f];
				h = h + z[g];
}
			
			e++;
		} while (h%2==p[e-1] && e < m);
		if (h % 2 == p[e - 1])sum = sum + 1;
	}



	cout << sum;


	return 0;
}

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

const int N=101;
LL W[N],V[N];

int main() {
    LL n,w;
    scanf("%lld %lld", &n, &w);
    REP(i,n) scanf("%lld %lld", W+i, V+i);
    vector<LL> ws;
    map<int,vector<LL>> mp;
    REP(i,n) {
        ws.push_back(W[i]);
        mp[W[i]].push_back(V[i]);
    }
    sort(ws.begin(),ws.end());
    ws.erase(unique(ws.begin(),ws.end()),ws.end());
    for ( int i:ws ) {
        sort(mp[i].rbegin(),mp[i].rend());
        for ( int j=1; j<mp[i].size(); j++ ) {
            mp[i][j]+=mp[i][j-1];
        }
    }
    if ( ws.size()==1 ) {
        LL k=w/ws[0];
        k=min(n,k);
        if ( k==0 ) cout << 0 << '\n';
        else cout << mp[ws[0]][k-1] << '\n';
    }
    if ( ws.size()==2 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                if ( ws[0]*i+ws[1]*j>w ) continue;
                LL res=0;
                if ( i>0 ) res+=mp[ws[0]][i-1];
                if ( j>0 ) res+=mp[ws[1]][j-1];
                ans=max(ans,res);
            }
        }
        cout << ans << '\n';
    }
    if ( ws.size()==3 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                for ( int k=0; k<=mp[ws[2]].size(); k++ ) {
                    if ( ws[0]*i+ws[1]*j+ws[2]*k>w ) continue;
                    LL res=0;
                    if ( i>0 ) res+=mp[ws[0]][i-1];
                    if ( j>0 ) res+=mp[ws[1]][j-1];
                    if ( k>0 ) res+=mp[ws[2]][k-1];
                    ans=max(ans,res);
                }
            }
        }
        cout << ans << '\n';
    }
    if ( ws.size()==4 ) {
        LL ans=0;
        for ( int i=0; i<=mp[ws[0]].size(); i++ ) {
            for ( int j=0; j<=mp[ws[1]].size(); j++ ) {
                for ( int k=0; k<=mp[ws[2]].size(); k++ ) {
                    for ( int l=0; l<=mp[ws[3]].size(); l++ ) {
                        if ( ws[0]*i+ws[1]*j+ws[2]*k+ws[3]*l>w ) continue;
                        LL res=0;
                        if ( i>0 ) res+=mp[ws[0]][i-1];
                        if ( j>0 ) res+=mp[ws[1]][j-1];
                        if ( k>0 ) res+=mp[ws[2]][k-1];
                        if ( l>0 ) res+=mp[ws[3]][l-1];
                        ans=max(ans,res);
                    }
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 3680
#include<stdio.h>
int tax(int p, int x){
    return p*(100.0+x)/100.0;
}
int main(void){
    int x, y, s, max;
    int i, j, tmp;
    while(1){
        max=0;
        scanf("%d%d%d",&x, &y, &s);
        if(x==0 && y==0 && s==0) break;
        for(i=1; i<s; i++){
            for(j=i; j<s; j++){
                if((tax(i,x)+tax(j,x))==s){
                    if((tmp=(tax(i,y)+tax(j,y))) > max){
                        max = tmp;
                    }
                }
            }
        }
        printf("%d\n",max);
    }
    return 0;
}



Measured memory_bytes: 2040
n = gets.to_i
s = gets.chomp
ans = 0
[*'0'..'9'].repeated_permutation(3) do |x, y, z|
  a = s.index(x, 0)
  b = s.index(y, a + 1) if a
  c = s.index(z, b + 1) if b

  ans += 1 if a && b && c
end

puts ans

Measured memory_bytes: 1916
N, L = map(int, input().split())

a = list(range(L, L + N))
sa = sum(a)
if a[0] * a[-1] <= 0:
    print(sa)
else:
    if a[0] < 0:
        print(sa - a[-1])
    else:
        print(sa - a[0])


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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;

    return 0;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        String[] siritori = new String[a];
        String end="";
        String head="";
        boolean chkFlg=true;
        for(int i=0;i<a;i++) {
        	siritori[i]=scanner.next();
        	if(i!=0) {
        		head=siritori[i].substring(0,1);
        		if(!head.equals(end)){
        			System.out.println("No");
        			chkFlg=false;
        			break;
        		}
        		for(int j=0;j<i;j++) {
        			if(siritori[j].equals(siritori[i])) {
        				System.out.println("No");
        				chkFlg=false;
        				break;
        			}
        		}
        	}
        	end=siritori[i].substring(siritori[i].length()-1, siritori[i].length());
        }
        if(chkFlg) {
        	System.out.println("Yes");
        }

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

#pragma GCC target("avx")


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

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a(x) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      } aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

template<const i64 M>
std::ostream& operator<<(std::ostream& os, const modint<M>& m) {
  os << m.value();
  return os;
}

const i64 MOD = 998244353;
using fp = modint<MOD>;

constexpr i64 A = 1e6 + 1;

i64 gcd(i64 a, i64 b) {
  while(b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int main() {

  vector<vector<int>> divs(A);
  rep(i,1,A) {
    for(i64 x = i; x <= A; x += i) {
      divs[x].emplace_back(i);
    }
  }

  std::vector<int> mu(A);
  mu[1] = 1;
  rep(x,2,A) {
    for(auto d: divs[x]) {
      if(d < x) mu[x] -= mu[d];
    }
  }
  std::vector<fp> g(A);
  rep(i,1,A) {
    g[i] = fp(i).pow(MOD - 2);
  }

  std::vector<fp> f(A);
  rep(x,1,A) {
    for(auto d: divs[x]) {
      if(mu[d] == 1) f[x] += g[x / d];
      if(mu[d] == -1) f[x] -= g[x / d];
    }
  }

  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 N;
  cin >> N;
  vector<fp> sum(A);
  fp ans = 0;
  rep(i,0,N) {
    i64 A;
    cin >> A;
    fp res = 0;
    for(auto d: divs[A]) {
      res += f[d] * sum[d];
      sum[d] += fp(A);
    }
    ans += res * fp(A);
  }
  cout << ans << endl;
}


Measured memory_bytes: 142240
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100025;
const int inf=0x3f3f3f3f;
int n,m;
int w[maxn];
ll v[maxn];
ll dp[maxn];
int main()
{
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    cin>>w[i]>>v[i];
    for (int i=1;i<=n;i++)
        for(int j=m;j>=w[i];j--)
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
    cout<<dp[m];
    return 0;
}


Measured memory_bytes: 4408