akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long name; long long dist;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};

ll const MAX = 505;
ll a[MAX][MAX],b[MAX][MAX], grid[MAX][MAX];

void f(ll x) {
	if (x == 0) {
		cout << '.';
	}
	else {
		cout << '#';
	}
}
int main() {
	ll h, w;
	cin >> h >> w;
	REP(i, 1, h) {
		REP(j, 1, w) {
			char c;
			cin >> c;
			if (c == '.') {
				grid[i][j] = 0;
			}
			else {
				grid[i][j] = 1;
			}
		}
	}
	REP(i, 1, h) {
		a[i][1] = b[i][w] = 1;
	}
	REP(i, 1, h) {
		REP(j, 2, w - 1) {
			if (i % 2 == 1) {
				a[i][j] = 1;
				b[i][j] = 0;
			}
			else {
				a[i][j] = 0;
				b[i][j] = 1;
			}
		}
	}
	REP(i, 1, h) {
		REP(j, 1, w) {
			if (grid[i][j] == 1) {
				a[i][j] = b[i][j] = 1;
			}
		}
	}
	REP(i, 1, h) {
		REP(j, 1, w) {
			f(a[i][j]);
		}
		cout << endl;
	}
	cout << endl;
	REP(i, 1, h) {
		REP(j, 1, w) {
			f(b[i][j]);
		}
		cout << endl;
	}
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int first = 0;
    int second = 0;
    bool d_check = false;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        if(first < A.at(i)){
            second = first;
            first = A.at(i);
            d_check = false;
        }else if(first == A.at(i)){
            second = first;
            first = A.at(i);
            d_check = true;
        }
        if(first > A.at(i) && second < A.at(i)){
            second = A.at(i);
        }
    }
    if(d_check){
        for(int i=0;i<N;i++){
            cout << first << endl;
        }
    }else {
        for(int i=0;i<N;i++){
            if(A.at(i) == first)    cout << second << endl;
            else
            {
                cout << first << endl;
            }
            
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 30;
int n, m, x, y, q, d; ll z, w = 0, sum; int ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
	cin >> n; vector<int> a(n);
	vector<int> b(1000010, 0);
	set<int> st;
	rep(i, n) {
		cin >> a[i];
		st.insert(a[i]);
		b[a[i]]++;
	}sort(ALL(a));
	for (int i : st) {
		int p = i;
		while (p <= 1000000) {
			b[p]++;
			p += i;
		}
	}
	rep(i, n) {
		if (b[a[i]] == 2)ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 17148
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

//////////////////
string str;
int size;

LL dfs(int pos,LL now,LL sum){
	if( pos == size ){
		return sum+now;
	}
	LL res = 0;
	LL ans = 0;
	///
	res = dfs(pos+1,now*10+str[pos]-'0',sum);
	ans += res;
	///
	res = dfs(pos+1,str[pos]-'0',sum+now);
	ans += res;

	return ans;
}
void solve(){
	cin >> str;
	size = str.size();
	LL ans = dfs(1,str[0]-'0',0);
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, cnt = 1, A = 0, B = 0, a[100010];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == a[i + 1])cnt++;
		else {
			if (cnt > 3) {
				if (A)B = a[i + 1];
				else A = B = a[i + 1];
			}
			else if (cnt > 1) {
				if (!A)A = a[i + 1];
				else B = a[i + 1];
			}
			cnt = 1;
		}
		if (B)break;
	}
	if (!B) {
		if (cnt > 3) {
			if (A)B = a[0];
			else A = B = a[0];
		}
		else if (cnt > 1) {
			if (!A)A = a[0];
			else B = a[0];
		}
	}
	cout << A * B << endl;
	return 0;
}

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}
template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    ll n;
    cin>>n;
    vector<int> a(n-1);
    rep(i,n-1)cin>>a[i];
    vector<int>ans(n);
    rep(i,n-1){
        ans[a[i]-1]++;
    }
    rep(i,n){
        print(ans[i]);
    }
    return 0;


}


Measured memory_bytes: 4724
import java.util.*;

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

        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        char[] S = new char[n];
        char[] T = new char[n];
        String ans = "" + s.charAt(0) + t.charAt(0);

        for(int i=1; i<=n-1; i++){
            S[i] = s.charAt(i);
            T[i] = t.charAt(i);
            ans = ans + S[i] + T[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import math
 
n = int(input())
 
def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            return
    print(target)
    exit(0)

num = 0
while True:
  trial_division(n+num)
  num += 1

Measured memory_bytes: 9016
package main

import "fmt"

func main() {
	var n, x, max int
	var s string
	fmt.Scan(&n, &s)

	for i := 0; i < n; i++ {
		word := s[i : i+1]
		if word == "I" {
			x++
		} else if word == "D" {
			x--
		}
		if x > max {
			max = x
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import numpy as np

def main():
    N, D = input_nums()
    Xs = {}
    for i in range(N):
        Xs[i] = np.array(input_nums())
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            a = np.sqrt(np.sum(np.square(Xs[i] - Xs[j])))
            if a == int(a):
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 21776
#include<bits/stdc++.h>
using namespace std ;
int main() {
 int a,b,c,d ;
 cin>>a>>b>>c>>d ;
 if(a+b>c+d) {
    cout<<"Left" ;
 }
 if(c+d>a+b) {
    cout<<"Right" ;
 }
 if(a+b==c+d) {
    cout<<"Balanced" ;
 }
}


Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
#mod = 10**9 + 7
mod = 998244353

A, B = rl()

if 1 <= A <= 9 and 1 <= B <= 9:
	print(A*B)
else:
	print(-1)


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

#define ll long long
#define ld long double
#define pr pair<ll,ll>
#define loop(i,n) for(ll i=0 ; i<n ; ++i)
#define rep(i,x,n) for(ll i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
const ll N=2e2 + 5;
ll n;
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
#ifndef ONLINE_JUDGE
   // freopen("in.txt", "rt" , stdin);
    // freopen("out.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
    cin>>n;
    vector<ll> div;
    for(ll i=1 ; i*i<=n ; i++) {
        if (n % i == 0) {
            div.push_back(i);
            div.push_back(n / i);
        }
    }
    ll sum=0;
    loop(i,div.size()){
        ll d=n/div[i];
        d--;
        if(d==0)continue;
        if(n%d==div[i])sum+=d;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 384
object Main extends App {
  var a = List(readInt,readInt,readInt,readInt,readInt)
  var min = 10
  var sum = 0
	a.foreach(i => {
    	if(i%10!=0&&min>i%10)min=i%10
      	if(i%10!=0)
		    sum += i+10-(i%10)
      	else
	    	sum += i
    })
  println(sum - 10 + min)
}

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

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

    int H[N];
    for (int i = 0; i < N; i++) cin >> H[i];

    int x, y;
    x = H[0];
    y = 1;

    for (int i = 1; i < N; i++) {
        if (x <= H[i]) {
            x = H[i];
            y ++;
        }
    }

    cout << y << endl;
}

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

int main() {
    int n, m=0, a[100];
    cin>>n;
    
    fill(a, a+100, 0);
    
    
    for(int i=2;i<=n;i++){
        bool b=true;
        for(int j=2;j<i;j++){
            if(i%j==0)b=false;
        }
        if(!b)continue;
        int t=n;
        int u=0;
        while(t>=i){
            u+=t/i;
            t/=i;
        }
        if(u>=74)a[74]++;
        if(u>=24)a[24]++;
        if(u>=14)a[14]++;
        if(u>=4)a[4]++;
        if(u>=2)a[2]++;
        
    }
    
    // 
    m+=a[74];
    
    m+=a[24]*(a[2]-1);
    m+=a[14]*(a[4]-1);
    
    m+=a[4]*(a[4]-1)*(a[2]-2)/2;
    cout<<m<<endl;
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int a,b,c;
int main(){
    scanf("%d %d %d",&a,&b,&c);
    printf("%d\n",(a+b-1)/b*c);
    return 0;
}

Measured memory_bytes: 3752
import sys
stdin = sys.stdin
from collections import deque

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, k = na()
h = na()

inf = 10**10
dp = [inf] * n
dp[0] = 0
for i in range(n-1):
    for j in range(1, k+1):
        if i + j <= n - 1:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
#print(dp)
print(dp[n-1])

Measured memory_bytes: 52444
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());
	const int a = s[0] + 1;

	s = AtCoder::replaceToInteger(AtCoder::input());
	const int b = s[0] + 1;

	s = AtCoder::replaceToInteger(AtCoder::input());
	const int c = s[0] + 1;

	s = AtCoder::replaceToInteger(AtCoder::input());
	const int x = s[0];

	int ans = 0;

	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			for (int k = 0; k < c; k++) {
				int buf = 0;
				buf += k * 50;
				buf += j * 100;
				buf += i * 500;
				if ( x == buf) {
					ans++;
				}
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N;  cin>>N;
  int d[10][10];
  rep(i,0,10)rep(j,0,10) d[i][j]=0;
  rep(i,1,N+1){
    string s = to_string(i);
    char f = s[0];  char la = s.back();
    if(f=='0' || la=='0') continue;
    d[f-'0'][la-'0']++;
  }
  ll res=0;
  rep(i,1,10){
    rep(j,1,10){
      res += d[i][j]*d[j][i];
    }
  }
  cout<<res<<endl;
  return 0;
}


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

int main() {
  int N, M, s = 0;
  cin >> N >> M;
  if (N >= M) {
    cout << 0 << endl;
  } else {
    vector<int> place(M);
    vector<int> delta(M - 1);
    for (int i = 0; i < M; i++) {
      cin >> place.at(i);
    }
    sort(place.begin(), place.end());
    for (int i = 0; i < M - 1; i++) {
      delta.at(i) = place.at(i + 1) - place.at(i);
    }
    sort(delta.begin(), delta.end());
    for (int i = 0; i < M - N; i++) {
      s += delta.at(i);
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){

  int h, m, s, os, a;

  scanf("%d", &s);

  h = s/3600;
  a = s%3600;
  m = a/60;
  s = a%60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}


Measured memory_bytes: 2148
x, n = [int(i) for i in input().split()]
tmp = input()
if len(tmp) == 0:
  print(x)
else:
  ps = set([int(i) for i in tmp.split()])
  e = 0
  while True:
    if (x - e) not in ps:
      print(x - e)
      break
    if (x + e) not in ps:
      print(x + e)
      break
    e += 1
  

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main() {
  int N;
  string s[100000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>s[i];
  for (int i(0);i<N;i++){
    sort(s[i].begin(),s[i].end());
  }
  sort(s,s+N);
  ll ans(0);
  ll cnt(1);
  for (int i(0);i<N-1;i++){
    if (s[i]==s[i+1]) cnt +=1;
    else {
      ans += cnt * (cnt -1) / 2;
      cnt = 1;
    }
  }
  ans += cnt * (cnt-1) / 2; 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

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

int main() {
	int N;
	cin >> N;
	vector<LL> A;
	LL s=0;
	for(int i=0;i<N;i++){
		LL a;
		cin >> a;
		s+=a;
		A.push_back(s);
	}
	LL ret=s;
	for(int i=0;i<A.size();i++){
		ret=min(ret,abs(s-2*A[i]));
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 2420
def d_even_relation(N, Nodes):
    from collections import deque
    graph = [{} for _ in range(N)]
    for u, v, w in Nodes:
        graph[u - 1][v - 1] = w
        graph[v - 1][u - 1] = w

    ans = [0] * N
    queue = deque([(-1, -1, 0)])
    while queue:
        previous, parent, child = queue.pop()
        if parent == -1:
            ans[child] = 0
        elif previous != child:
            length = graph[parent][child]
            if length % 2 == 0:
                ans[child] = ans[parent]
            else:
                ans[child] = 1 if ans[parent] == 0 else 0
        for k in graph[child].keys():
            if parent != k:
                queue.appendleft((parent, child, k))
    return '\n'.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation(N, Nodes))

Measured memory_bytes: 104920
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> a(H+2,vector<char>(W+2));
  REP(i, H+2){
    if(i==0||i==H+1){
      REP(j,W+2){
        a.at(i).at(j) = '#';
      }
    }else{
      REP(j, W+2){
        if(j==0||j==W+1){
          a.at(i).at(j)  = '#';
        }else{
          cin >> a.at(i).at(j);
        }
      }
    }
  }

  REP(i,H+2){
    REP(j,W+2){
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print('F')
        m = -999
    if m + f >= 80:
        print('A')
    if 80 > m + f and m + f >= 65:
        print('B')
    if 65 > m + f and m + f >= 50:
        print('C')
    if 50 > m + f and m + f >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
    if 30 > m + f >= 0:
        print('F')

Measured memory_bytes: 7652
#include <bits/stdc++.h>
using namespace std;
int main(){
long long A, B, K;
cin >> A >> B >> K;
long long ansA, ansB;

if (A >= K) {
    ansA = A - K;
    ansB = B;
}
else if (B >= K - A) {
    ansA = 0;
    ansB = B - K + A;
}
else {
    ansA = 0;
    ansB = 0;
}
cout << ansA << " " << ansB << endl;
}

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

using namespace std;

long long N, K;
 
int main() {
  cin >> N >> K;
  
    long long res = 0;
    for (long long b = K+1; b <= N; ++b) {
        long long tmp = min(b-1, b-K);
        long long A = N - (b-1);
        long long B = N-K;
        long long add = (A/b) * (b - K);
        if (B/b == A/b + 1) add += (B%b) + 1;
      
        tmp += add;
        res += tmp;
    }
  
  cout << res << endl;
    
}
 

   

Measured memory_bytes: 256
//
//  AT3873 [ABC086A] Product.cpp
//  Algorithm
//
//  Created by SkyGao on 2020/2/13.
//  Copyright © 2020 skygao. All rights reserved.
//

#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#define re regsiter
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    a=a&1,b=b&1;
    if(a&b)
        printf("Odd");
    else
        printf("Even");
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i

six_bank = (1..10).map { |i| 6 ** i }
nine_bank = (1..10).map { |i| 9 ** i }

dp = Array.new(N + 1, Float::INFINITY)
dp[N] = 0

N.downto(1) do |i|
  next if dp[i] == Float::INFINITY

  six_bank.each do |s|
    break if i - s < 0

    t = dp[i] + 1
    dp[i - s] = t if dp[i - s] > t
  end

  nine_bank.each do |n|
    break if i - n < 0

    t = dp[i] + 1
    dp[i - n] = t if dp[i - n] > t
  end

  t = dp[i] + 1
  dp[i - 1] = t if dp[i - 1] > t
end

puts dp[0]


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

int main(){
  int a[3][3], b[10];
  bool result[3][3];
  
  rep(i,3)rep(j,3) cin >> a[i][j];
  
  int n;
  cin >> n;
  
  rep(i,n) cin >> b[i];
  rep(i,n)rep(j,n){
    result[i][j] = false;
    rep(k,n)if(a[i][j] == b[k]) result[i][j] = true;
  }
  
  string ans="No";
  rep(i,3)if(result[i][0] && result[i][1] && result[i][2]) ans = "Yes";
  rep(i,3)if(result[0][i] && result[1][i] && result[2][i]) ans = "Yes";
  if(result[0][0] && result[1][1] && result[2][2]) ans = "Yes";
  if(result[0][2] && result[1][1] && result[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}


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

int solve();
vector<pair<int,int> > shuffle(vector<pair<int,int> > vec,int i);

int N,M,P,Q,R;
int X[5010],Y[5010];

int main()
{
    while(scanf("%d",&N),N)
    {
        scanf("%d",&M);
        scanf("%d%d%d",&P,&Q,&R);
        for(int i = 0; i < M; i++)
        {
            scanf("%d%d",&X[i],&Y[i]);
        }
        printf("%d\n",solve());
    }
}

vector<pair<int,int> > shuffle(vector<pair<int,int> > vec,int i)
{
    vector<pair<int,int> > new_vec;
    for(int j = 0; j < vec.size(); j++)
    {
        int l = vec[j].first,r = vec[j].second;
        if(l <= X[i] && r <= X[i])
        {
            new_vec.push_back(make_pair(l + N - X[i],r + N - X[i]));
            continue;
        }
        if(l <= X[i] && X[i] < r && r <= Y[i])
        {
            new_vec.push_back(make_pair(l + N - X[i],N));
            new_vec.push_back(make_pair(N - Y[i] + 1,r + N - X[i] - Y[i]));
            continue;
        }
        if(X[i] < l && l <= Y[i] && X[i] < r && r <= Y[i])
        {
            new_vec.push_back(make_pair(l + N - X[i] - Y[i],r + N - X[i] - Y[i]));
            continue;
        }
        if(X[i] < l && l <= Y[i] && Y[i] < r)
        {
            new_vec.push_back(make_pair(l + N - X[i] - Y[i],N - X[i]));
            new_vec.push_back(make_pair(1,r - Y[i]));
            continue;
        }
        if(Y[i] < l && Y[i] < r)
        {
            new_vec.push_back(make_pair(l - Y[i],r - Y[i]));
            continue;
        }
        if(l <= X[i] && Y[i] < r)
        {
            new_vec.push_back(make_pair(l + N - X[i],N));
            new_vec.push_back(make_pair(N - Y[i] + 1,N - X[i]));
            new_vec.push_back(make_pair(1,r - Y[i]));
            continue;
        }
    }
    return new_vec;
}

int solve()
{
    int ANS = 0;
    vector<pair<int,int> > vec;
    vec.push_back(make_pair(1,R));
    for(int i = 0; i < M; i++)
    {
        vec = shuffle(vec,i);
    }
    for(int i = 0;i < vec.size(); i++)
    {
        int l = vec[i].first,r = vec[i].second;
        int a = max(l,P),b = min(r,Q) + 1;
        ANS += max(0,b - a);
    }
    return ANS;
}

Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int N, K;
    vector<int> h;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        h.push_back(x);
    }
    sort(h.begin(), h.end(), greater<int>());

    int ans = 1000000000;
    for (int i = 0; i < N - K + 1; i++)
    {
        int sub = h[i] - h[i + (K - 1)];
        if (sub < ans)
        {
            ans = sub;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }
    
    int replaceCnt = 0;
    int start = 0;
    for(int i = 0; i < n; i++){
        int min = d[start], pos = start;
        for(int k = start; k < n; k++){
            if(d[k] < min){
                min = d[pos = k];
            }
        }
        if(pos != start) replaceCnt++;
        d[pos] = d[start];
        d[start++] = min;
    }
    
    for(int i = 0; i < n; i++){
        cout << (!i ? "" : " ") << d[i];
    }
    cout << endl << replaceCnt << endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sll set<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std;

void solve(){
	int n,k;
	cin>>n>>k;

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

	sort(a.begin(), a.end());
	int ans=0;
	for(int i=0;i<k;i++)
		ans+=a[i];

	cout<<ans<<endl;
}
 
int main(){
    IOS;
    int q=1;
    //cin>>q;
    while(q--){
        solve();
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,c=0;
    cin>>x;
    ll y[x];
    ll ans=0;
    bool b=false;
    ll mn=1e9;
    for (int i=0;i<x;i++){
        cin>>y[i];
        if (y[i]<0)
        c++;
        ans+=abs(y[i]);
        mn=min(mn,abs(y[i]));
    }
    cout<<(c%2==0?ans:ans-2*abs(mn))<<endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    bool zero = false;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) zero = true;
    }

    if (zero) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1;
    for (int i = 0; i < N; i++) {
        if (A[i] > 1000000000000000000LL / ans) {
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }

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

Measured memory_bytes: 4052
s = input()
dp = [[0, 0] for i in range(len(s))]
dp[0][0] = int(s[0])
dp[0][1] = 11 - int(s[0])
for i in range(1, len(s)):
  dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + int(s[i])
  dp[i][1] = min(dp[i - 1][0] + 11 - int(s[i]), dp[i - 1][1] + 9 - int(s[i]))
print(min(dp[-1][0], dp[-1][1]))

Measured memory_bytes: 137916
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int h, w, k; cin >> h >> w >> k;
  vector<vector<int>> g(h, vector<int> (w, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c; cin >> c;
      if (c == '#') g[i][j] = 1;
    }
  }
  
  lint ans = 0;
  for (int x = 0; x < (1 << h); x++) {
    for (int y = 0; y < (1 << w); y++) {
      auto gg = g;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if ((x & (1 << i)) or (y & (1 << j))) {
            gg[i][j] = 0;
          }
        }
      }

      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          cnt += gg[i][j];
        }
      }

      if (cnt == k) ans++;
    }
  }

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


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

int main(){
      int x;cin >> x;
      int b = 1;
      int p = 2;
      set<int> ans;
      if(x == 1)return cout << 1, 0;
      for(int i = b;i < x;i++){
            for(int j = p;j < x;j++){
                  if(pow(i, j) > x)break;
                  else ans.insert(pow(i, j));
            }
      }
      cout << *(--ans.end());
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

T_H, T_A, A_H, A_A = [int(x) for x in stdin.readline().rstrip().split()]

while 1:
    T_H -= A_A
    A_H -= T_A
    if A_H <= 0:
        print("Yes")
        break
    elif T_H <= 0:
        print("No")
        break

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

int bubbleSort(int N, int* A) {
	bool flag = true;
	int ret = 0;
	while (flag) {
		flag = false;
		for (int j = N - 1; j > 0; j--) {
			if (A[j] < A[j - 1]) {
				int temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
				flag = true;
				ret++;
			}
		}
	}
	return ret;
}

int main()
{
	int N = 0, c = 0;
	int A[100] = {};
	cin >> N;
	while (c < N) {
		cin >> A[c];
		c++;
	}
	int swapCount = bubbleSort(N, A);
	for (int i = 0; i < N; i++) {
		if(i == 0) cout << A[i];
		else cout << " " << A[i];
	}
	cout << endl << swapCount << endl;
    return 0;
}




Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;


int main(){
    int apple_num, L;
    cin >> apple_num;
    cin >> L;

    int lower, higher;
    lower = L;
    higher = apple_num + L - 1;

    int sum = (lower + higher)*apple_num/2;

    if(lower==0 || higher ==0){
        cout << sum << endl;
    }else if(lower*higher < 0){
        cout << sum << endl;
    }else if(lower*higher > 0){
        if(lower > 0){
            cout << sum-lower << endl;
        }else{
            cout << sum-higher << endl;
        }
    }

    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long A; string b; cin >> A >> b;
    long long B = 0;
    for (auto &x: b) {
        if (x == '.') continue;
        B = B * 10 + x - '0';
    }
    long long C = A * B / 100;
    cout << C << "\n";
    
    return 0;
}

Measured memory_bytes: 3612
a,b = [],[]
while True:
    (a,b) = [int(x) for x in input().split()]
    if a == b == 0:
        break
    for x in range(a):
        for y in range(b):
            if (x + y) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()

Measured memory_bytes: 6804
N = int(input())
ans = 10**13
Y = [9**i for i in range(1, 10)] + [6**i for i in range(1, 10)]
Y = sorted(Y, reverse=True)
for i in range(N+1):
    tmp = 0
    n = N-i
    for j in range(10, -1, -1):
        if i // 9**j > 0:
            tmp += i // 9**j
            i %= 9**j
    for j in range(10, -1, -1):
        if n // 6**j > 0:
            tmp += n // 6**j
            n %= 6**j
        # print(ans, j)

        # print(ans, j, N)
    ans = min(ans, tmp)

print(ans)

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

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll func(ll arr[],ll n,ll sum)
{
    ll dp[sum+1]={0};
    dp[0]=1;
    for(ll i=0;i<n;i++)
        for(ll j=arr[i];j<=sum;j++)
            dp[j] = dp[j] + dp[j-arr[i]];
    return dp[sum];
}

int main()
{
    fast();
    ll n;
    cin>>n;

    cout<<"Christmas ";
    while(n<25)
    {
        cout<<"Eve ";
        n++;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;

int main() {
	int j=0,n,s[110],a;
	string b,d="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	while (1) {
		for (int i = 0; i < 110; i++) {
			s[i] = 0;
		}
		cin >> n;
		if (!n)break;
		j = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &s[i]);
			j++;
		}
		cin >> b;
		for (int i = 0; i < b.size(); i++) {
			a=d.find(b[i])- s[i%j];
			if (a < 0)a += 52;
			b[i] = d[a];
		}
		cout << b << endl;
	}
	return 0;
}

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

int main() {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  }
  else if (R < 2800) {
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	string s;
    IN(s);
    char a[2]={'L','R'};
    bool f=true;
    REP(i,SZ(s)){
        if(s[i]==a[i%2]){
            f=false;
            break;
        }
    }
    if(f)OUT("Yes");
    else OUT("No");
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

a = len(s)
b = len(t)

ans = []

for i in range((a-b)+1):
    an = 0
    for j in range(b):
        if s[i+j] != t[j]:
            an += 1
            
    ans.append(an)

print(min(ans))

Measured memory_bytes: 8956
def solve():
    cnt = 0
    for i in range(N):
        tmp = 0
        while a[i]%2 == 0:
            a[i] /= 2
            tmp += 1  
        cnt += tmp
    print(cnt)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))
    solve()


Measured memory_bytes: 10152
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
	int a,b,k,i;
	scanf("%d %d %d",&a,&b,&k);
	for(i=a;i<a+k;i++){
		if(i>b) return 0;
		printf("%d\n",i);
	}
	for(i=b-k+1;i<=b;i++){
		if(i>b) return 0;
		if(i>=a+k) printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    int tc = 1;
//    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
# きたない。。。。
def get_formula(a,b,c,d) :
	for f1 in range(2) :
		s = str(a)
		if (f1 == 0) :
			s += "+"
		else : 
			s += "-"
		
		s += str(b)
		for f2 in range(2) :
			s2 = s
			if (f2 == 0) :
				s2 += "+"
			else : 
				s2 += "-"
			
			s2 += str(c)
			for f3 in range(2) :
				s3 = s2
				if (f3 == 0) :
					s3 += "+"
				else : 
					s3 += "-"
				
				s3 += str(d)
				if (eval(s3) == 7) :
					return s3

a,b,c,d = [int(i) for i in list(input())]

print(get_formula(a,b,c,d) + "=7")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
string s="";
int main(){
    unsigned long long int N;
    cin>>N;
    while(N){
        s=(char)('a'+(N-1)%26)+s;
        N--;
        N/=26;
    }
    cout<<s;
    return 0;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 300000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

pair<ll, ll> solve(ll n, ll m)
{
    if (n * m % 2 == 0)
        return mp(n * m / 2, n * m / 2);
    else
    {
        if (n > m)
            swap(n, m);
        return mp(n * ((m + 1) / 2), n * (m / 2));
    }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, m;
    cin >> n >> m;
    ll ans = big;
    rep(i, 1, n)
    {
        auto p = solve(n - i, m);
        ans = min(ans, max(i * m, p.fi) - min(i * m, p.se));
    }
    rep(i, 1, m)
    {
        auto p = solve(n, m - i);
        ans = min(ans, max(i * n, p.fi) - min(i * n, p.se));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int mod=1e9+7;
long long dp[2002];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,j,n;
    cin >> n;
    dp[0]=1;
    for(i=1;i<=n;i++)
    {
        for(j=3;j<=i;j++)
        {
            dp[i]+=dp[i-j];
            dp[i]%=mod;
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 3644
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=998244353;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[LIM] = {0};
ll dp2[LIM] = {0};

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

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

ll fastpow(ll a, ll p){
	if(p == 0) return 1;
	ll z = fastpow(a, p/2);
	z = mul(z, z);
	if(p%2) z = mul(a, z);
	return z;
}
	
int main(){
	fastio;

	int n; cin>>n;
	ll a[n]; forn(i,n) cin>>a[i];
	ll sum = 0;
	dp[0] = 1;
	dp2[0] = 1;
	forn(i,n){
		sum += a[i];
		rforn(j,LIM-1){
			dp[j+a[i]] = add(dp[j+a[i]], dp[j]);
			dp[j] = mul(dp[j], 2);
			dp2[j+a[i]] = add(dp2[j+a[i]], dp2[j]);
		}
	}
	ll ans = 0;
	forn(i,LIM){
		if(2*i >= sum){
			ans = add(ans, dp[i]);
		}
	}

	if(sum % 2 == 0){
		ans -= dp2[sum/2];
	}

	ans = mul(ans, 3);
	ll fin = fastpow(3, n);
	fin -= ans;
	fin %= MOD;
	if(fin<0) fin += MOD;
	cout<<fin<<ln;

	return 0;
}

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

// -------------------
// ここから先は変更しない
// -------------------
int main()
{
    long N;
    std::cin >> N;
    vector<long> vec(N);
    for (long i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    std::sort(vec.begin(), vec.end());

    long count = 2;
    long ans = vec.at(vec.size() - 1);
    vec.pop_back();
    while (count < N)
    {
        long add_num = vec.at(vec.size() - 1);
        ans += add_num * 2;
        vec.pop_back();
        count += 2;
        if (count > N)
        {
            ans = ans - add_num;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;


int main() {
  ll h, w, m;
  cin>>h>>w>>m;
  map<P,ll> v;
  vector<ll> H(h,0);
  vector<ll> W(w,0);
  vector<ll> H1;
  vector<ll> W1;

ll maxh=0;
ll maxw=0;
  rep(i,m){
    P temp;

    cin>>temp.first>>temp.second;
    temp.first--;
    temp.second--;
    v[temp]++;
    H[temp.first]++;
    W[temp.second]++;
    maxh=max(maxh,H[temp.first]);
    maxw=max(maxw,W[temp.second]);
  }
  rep(i,h){
    if (H[i]==maxh){
  //    cout<<i<<endl;
      H1.push_back(i);
    }
  }
  rep(i,w){
    if (W[i]==maxw){
      W1.push_back(i);
    //  cout<<i<<endl;

    }
  }
  ll ans=maxh+maxw;
//  cout<<maxh<<' '<<maxw<<endl;

  ll t=-1;
  if(H1.size()*W1.size()>m){
    cout<<ans;
    return 0;
  }
  for(ll i:H1)for(ll j:W1){

  //  cout<<i<<' '<<j<<endl;
    if (v[make_pair(i,j)]<=0){
      t=0;
    }
  }
  ans+=t;
  cout<<ans;

}


Measured memory_bytes: 34952
/* 北さん参考 */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> st;
    REP(i, n) {
        cin >> a[i];
        st.insert(a[i]);
    }
    int ans = st.size();
    sort(a.begin(), a.end());

    int p = a[0], cnt = 1;
    int gusu = 0;

    REPN(i, 1, n) {
        if(p == a[i]) {
            cnt++;
        } else {
            if(cnt % 2 == 0) gusu++;
            cnt = 1, p = a[i];
        }
    }

    if(cnt % 2 == 0) gusu++;

    //cout << ans << endl;

    if(gusu % 2 == 0) {
        cout << ans << endl;
    } else {
        cout << ans-1 << endl;
    }


    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int64_t G;//最小公倍数
  cin >> G;
  for(int i = 1; i < N; i++){
    int64_t T;
    cin >> T;
    int64_t A = max(G, T);
    int64_t B = min(G, T);
    for(int j = 1; true; j++){
      if(j*A % B == 0){
        G = j*A;
        break;
      }
    }
  }
  
  cout << G << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const int MAXN = 100500;
const int MOD = 1000000007;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	//system("pause");
	return 0;
}

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

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

	if ( a+b > c+d ){
		cout << "Left" << endl;
	}
	else if ( a+b == c+d ){
		cout << "Balanced" << endl;
	}
	else if ( a+b < c+d ){
		cout << "Right" << endl;
	}
}



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

int main() {
  int A,B,M;
  cin >>A>>B>>M;
  int a[A],b[B],x[M],y[M],c[M];
  for (int i=1; i<=A; ++i){
    cin >> a[i];
  }
  for (int i=1; i<=B; ++i){
    cin >> b[i];
  }
  for (int i=1; i<=M; ++i){
    cin >> x[i];
    cin >> y[i];
    cin >> c[i];
  }
  int p=a[1],q=b[1];
  for (int i=2; i<=A; ++i){
    if(a[i]<p){
      p = a[i];
    }
  }
  for (int i=2; i<=B; ++i){
    if(b[i]<q){
      q = b[i];
    }
  }
  int min = p+q;
  for (int i=1; i<=M; ++i){
    if(a[x[i]]+b[y[i]]-c[i]<min){
      min = a[x[i]]+b[y[i]]-c[i];
    }
  }
  cout << min;
  return 0;
}


Measured memory_bytes: 2176