akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BITS(n, num) std::bitset<(n)>((num)).to_string()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, H;
  cin >> N >> H;
  vl A(N, 0), B(N, 0);
  REP(i, N) cin >> A[i] >> B[i];
  ll maxa = MAX(A);
  sort(ALL(B), greater<ll>());
  ll ans = 0;
  AUTO(b, B) {
    if (b >= maxa) {
      H -= b;
      ans++;
    }
    if (H <= 0)
      break;
  }
  if (H <= 0) {
    cout << setprecision(15) << ans << endl;
    return 0;
  } else {
    cout << setprecision(15) << ans + (ll)ceil((double)H / maxa) << endl;
    return 0;
  }
  return 0;
}


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

int main(){
	int N;
	bool flag = false;
	cin >> N;
	vector<string> W = vector<string>(N, "");
	for(int cnt = 0; cnt < N ; cnt++){
		cin >> W[cnt];
	}
	for(int cnt = 1; cnt < N ; cnt++){
		if(W[cnt][0] != W[cnt - 1][W[cnt - 1].length() - 1]){
			flag = true;
			break;
		}
		for(int check = 0; check < cnt ; check++){
			if(W[check] == W[cnt]){
				flag = true;
				break;
			}
		}
	}
	if(!flag) cout << "Yes";
	else cout << "No";

	return 0;
}


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


// æ­Ôá¤Æ±ëB
// âè¶É¢ÄÈ­ÄàâèZbgÍ¡Åæªª0ÅI¹Å éB
// âèZbgÌJèÔµÉú»Rê

// 2011/10/18

//@0113 zÂ¬
public class Main {

	
	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		int[] ri = readIntArray();
		if (ri == null) 
			return false; // ¨µÜ¢

		int p = ri[0];
		int q = ri[1];

		int w = p * 10;
	
		String s = "";
		String t = null; // zÂµ½Æ«É^^^
		List<Integer> amari = new ArrayList<Integer>();
		while(w != 0) {
			int idx = amari.indexOf(w);
			if (idx >= 0) {
				// zÂµ½
				t = "";
				for(int i = 0; i < amari.size(); i++) {
					if (i < idx) {
						t += " ";
					}
					else {
						t += "^";
					}
				}
				break;
			}
			amari.add(w);
			int sh = w / q;
			s += "" + sh;
			w = (w % q) * 10;
		}

		// ðÌ\¦
		System.out.printf("%s\n", s);
		if (t != null)
			System.out.printf("%s\n", t);
		
		return true; // ³íI¹ Ö
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

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

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "1 459550\n";

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		//int N = readIntArray()[0];

		for(int i = 0; /*i < N*/; i++) {
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè1sªÌXy[XæØèÌ®lðÇÞ
	// EOFÌêÍnullðÔ·
	private static int[] readIntArray() throws IOException {
		
		String s = reader.readLine();
		if (s == null)
			return null;
		String[] sp = s.split(" ");
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

Measured memory_bytes: 12000
#include <iostream>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int max_second = 0;
  int max_num = 0;
  int max_index = -1;
  int max_idnex_second = -1;
  rep(i, n){
    int a;
    cin >> a;
    if(max_num < a){
      max_second = max_num;
      max_idnex_second = max_index;
      max_num = a;
      max_index = i;
    }else if(max_second < a){
      max_idnex_second = i;
      max_second = a;
    }
  }

  rep(i, n){
    if(max_index == i){
      cout << max_second << endl;
    }else{
      cout << max_num << endl;
    }
  }

  return 0;
}

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

int main() {
	string s;
  string ans = "CODEFESTIVAL2016";
  cin >> s;
  int a = 0;
  for(int c = 0;c<16;c++){
	if(s[c] != ans[c]){
		a++;
    }
  }
  cout << a++;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int r;
  int c;
  std::cin >> r >> c;

  int *sheet = new int[r * c];
  int *rsum = new int[r];
  int *csum = new int[c];
  int sum = 0;
  for(int i = 0; i < r; ++i) {
    rsum[i] = 0;
  }
  for(int j = 0; j < c; ++j) {
    csum[j] = 0;
  }

  for(int i = 0; i < r; ++i) {
    for(int j = 0; j < c; ++j) {
      std::cin >> sheet[i * c + j];
      csum[j] += sheet[i * c + j];
      rsum[i] += sheet[i * c + j];
      sum += sheet[i * c + j];
    }
  }

  for(int i = 0; i <= r; ++i) {
    for(int j = 0; j <= c; ++j) {
      if(i == r && j == c) {
        std::cout << sum << std::endl;
      }
      else if(i == r) {
        std::cout << csum[j] << " ";
      }
      else if(j == c) {
        std::cout << rsum[i] << std::endl;
      }
      else {
        std::cout << sheet[i * c + j] << " ";
      }
    }
  }

  delete[] sheet;
  delete[] rsum;
  delete[] csum;

  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
using namespace std;
long long dp[100010] = {};
int main(){
	int i,j,n,q;
	string s;
	cin >> n >> q >> s;
	for(i=1;i<=n;i++){
		dp[i] = dp[i-1];
		if(i!=1 && s[i-1]=='C' && s[i-2]=='A'){
			dp[i]++;
		}
	}
	for(i=0;i<q;i++){
		int l,r;
		cin >> l >> r; l--;
		int x = dp[r] - dp[l];
		if(l!=0 && s[l]=='C' && s[l-1]=='A') x--;
		cout << x << endl;
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> n;
	cin >> s;
	ll res = 0;
	for (ll j = 1; j < n - 1; j++) {
		ll cnt = 0;
		map<char, ll>mpa;
		map<char, ll>mpb;
		rep(i, n) {
			if (i < j) {
				mpa[s[i]]++;
			}
			else {
				mpb[s[i]]++;
			}
		}
		for (char k = 'a'; k <= 'z'; k++) {
			if (mpa[k] > 0 && mpb[k] > 0) {
				cnt++;
			}
		}
		chmax(res, cnt);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")
	    cout<<"Yes";
	else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=5e3+7;
const int mod=1e9+7;
int f[maxn][2];
int dp[maxn][2];
int main()
{
	int n;
	cin>>n;
	int a,b;
	cin>>a>>b;
	if(a>b) swap(a,b);
	dp[0][0]=dp[0][1]=1;
	f[0][1]=1;
	for(int i=0;i<=b+1;i++)
	{
		for(int j=a;i+j<=b+1;j++)
			f[i+j][1]=(f[i+j][1]+f[i][0])%mod;
		for(int j=1;i+j<=b+1;j++)
			f[i+j][0]=(f[i+j][0]+f[i][1])%mod;
		//dbg(i,f[i][0],f[i][1]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<a&&i+j<=n;j++)
			dp[i+j][0]=(dp[i+j][0]+dp[i][1])%mod;
		for(int j=1;j<b&&i+j<=n;j++)
		{
			dp[i+j][1]=(dp[i+j][1]+(ll)dp[i][0]*f[j+(i==0)+(i+j==n)][0]%mod)%mod;
		}
	//	dbg(i,dp[i][0],dp[i][1]);
	}
	int tot=1;
	for(int i=1;i<=n;i++) tot=tot*2%mod;
	print((tot-(dp[n][0]+dp[n][1])%mod+mod)%mod);
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
    int a,b,c;
    int d,e,f;
    int min;
    
    char buf[256];
    fgets(buf,256,stdin);
    sscanf(buf,"%d%d%d", &a, &b, &c);
    
    d = a + b;
    e = a + c;
    f = b + c;
    
    min = d;
    if(e < min){
        min = e;
    }
    if(f < min){
        min = f;
    }
    
    printf("%d \n", min);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||a==12||a==14||a==15||a==16||a==18||a==20||a==21||a==24||a==25||a==27||a==28||a==30||a==32||a==35||a==36||a==40||a==42||a==45||a==48||a==49||a==54||a==56||a==63||a==64||a==72||a==81){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#define H 251

int main(){
  int A[H];
  int i,n;

  scanf("%d",&n);
  for(i = 1; i <= n; i++)
    scanf("%d",&A[i]);
  for(i = 1; i <= n; i++) {
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2 > 0) printf("parent key = %d, ",A[i/2]);
    if(2*i <= n) printf("left key = %d, ",A[2*i]);
    if(2*i + 1 <= n) printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n, k;
lin x[100001];

lin solve(lin bg)
{
    lin ed = bg + k - 1;

    lin res =
        x[ed] < 0 ? abs(x[bg]) :
        x[bg] > 0 ? x[ed]:
        (abs(x[bg]) + x[ed] + min(abs(x[bg]), x[ed]));

    return res;
}

int main(void)
{

    cin >> n >> k;
    rep(i, n)
    {
        cin >> x[i];
    }

    lin res = solve(0);
    rep(i, n - k + 1)
    {
        res = min(res, solve(i));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
  int W,H,N;
  scanf("%d %d %d",&W,&H,&N);
  int xl = 0,xr = W,yu = H,yd = 0;
  int x[N],y[N],a[N];
  for(int i = 0;i < N;i++){
    scanf("%d %d %d",&x[i],&y[i],&a[i]);
    if(a[i] == 1){
      if(xl < x[i]){
        xl = x[i];
      }
    }else if(a[i] == 2){
      if(xr > x[i]){
        xr = x[i];
      }
    }else if(a[i] == 3){
      if(yd < y[i]){
        yd = y[i];
      }
    }else if(a[i] == 4){
      if(yu > y[i]){
        yu = y[i];
      }
    }
  }
  if(xr < xl || yu < yd){
    xr = xl;
  }
  printf("%d\n",(xr - xl) * (yu - yd));
  return 0;
}

Measured memory_bytes: 128
from sys import stdin, stdout
from collections import defaultdict
def readLine_str_list():return list(map(str, stdin.readline().split()))
def readLine_int_list():return list(map(int, stdin.readline().split()))
def readAll_str(): return list(list(map(str,i.split())) for i in stdin.read().split("\n"))
def g_twoD_list(p,q): return [[0 for i in range(p)] for j in range(q)]


def main():
    h,w = readLine_int_list()
    a = g_twoD_list(w,h)
    b = defaultdict(lambda: 0)
    _h = 0
    _w = 0
    for l in readAll_str():
        for i in l:
            _w = 0
            for j in i:
                b[(_h,_w)] = j
                _w += 1
            _h += 1
            
    dir_b = [(-1,0), (1,0), (0,-1), (0,1), (-1,-1), (-1,1), (1,-1), (1,1)]
    for i in range(h):
        for j in range(w):
            cnt = 0
            for d in dir_b:
                r = b[(i+d[0], j+d[1])]
                if r == '#':
                    cnt += 1
            if b[(i,j)] == '.':
                b[(i,j)] = str(cnt)
    # print(b)
    for i in b:
        if 0 <= i[0] < h and 0 <= i[1] < w:
            a[i[0]][i[1]] = b[i]
            
    for i in a:
        print(''.join(i))
if __name__ == "__main__":
    main()


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

typedef long long ll;

ll N, K, tot;

int main() {
	scanf("%lld%lld", &N, &K);

	for (ll b = 1; b <= N; ++b) {
		for (ll nb = 0; nb <= N; nb += b) {
			tot += max(0LL, min(nb + b - 1, N) - (nb + K) - (nb + K == 0) + 1);
		}
	}

	printf("%lld\n", tot);
}

Measured memory_bytes: 256
#C
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = 1000
a = [i for i in range(0,150)]



p_dif = set(a) - set(p)
#print(p_dif)

for i in p_dif:
    if tmp > abs(i-x):
        tmp = abs(i-x)
        result = i
        
        
print(result)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    // ll N,S,K;
    ll a,b,c;
    cin >> a ;

cout << a*a <<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
    double PI = acos(-1);
    double a = 0, b = 0, c = 0, C = 0, S = 0, L = 0, h = 0;
    scanf("%lf %lf %lf", &a, &b, &C);
    
    double radC = C * PI / 180;
    c = sqrt(a*a + b*b - 2*a*b*cos(radC));
    S = a * b * sin(radC) / 2.0 ;
    L = a + b + c;
    h = S * 2 / a;
    
    printf("%lf\n%lf\n%lf\n", S, L, h);
    
    return 0;
}


Measured memory_bytes: 2952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    out("Possible");
  else
    out("Impossible");
}
int main(void) { solve(); }


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
signed main(){
  int N,M,C,ans=0;
  cin>>N>>M>>C;
  vi B(M);
  rep(i,0,M) cin>>B[i];
  rep(i,0,N){
    int sum=C;
    rep(j,0,M){
      int X;
      cin>>X;
      sum+=B[j]*X;
    }
    if(sum>0) ans++;
  }
  cout<<ans<<endl;
}

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

int N, Q, K;
vector<vector<P> > G;
vector<int> dist;

void dfs(int pre, int n, int c) {
  if ( dist[n] != -1 ) return;
  dist[n] = c;
  for ( P &p: G[n] ) {
    if ( pre == p.first ) continue;
    dfs(n, p.first, c+p.second);
  }
  return;  
}

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

  cin >> N;
  G.resize(N);
  dist.resize(N, -1);  
  REP(i, N-1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back(P(b, c));
    G[b].push_back(P(a, c));
  }

  cin >> Q >> K;
  K--;
  dfs(-1, K, 0);
  while ( Q-- ) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << dist[x] + dist[y] << endl;    
  }

  return 0;
}


Measured memory_bytes: 15604
#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 <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int n,m;
vector<int> path[5001];
int state[5001];
vector<int> order;
bool ng;
void search(int i){
	if(state[i]==1){
		ng=true;
		return;
	}
	state[i]=1;
	for(auto j:path[i]){
		if(state[j]!=2){
			search(j);
		}
	}
	state[i]=2;
	order.push_back(i);
}
int main() {
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		path[a].push_back(b);
	}
	for(int i=1;i<=n;i++){
		if(state[i]==0){
			search(i);
		}
	}
	if(ng){
		cout << 0 << endl;
		return 0;
	}
	reverse(order.begin(),order.end());
	for(auto i:order){
		cout << i << endl;
	}
	for(int i=0;i<n-1;i++){
		if(find(path[order[i]].begin(),path[order[i]].end(),order[i+1])==path[order[i]].end()){
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;cin>>N>>K;
    ll P=N/K;
    ll ans=min(abs(N-K*P),abs(N-K*(P+1)));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    cout << (N*A >= B ? B : N*A)  << endl;
}

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

using namespace  std;
int main()
{
	int n; cin >> n;
	string s; cin >> s;
	string s1;
	string s2;
	for (int i = 0; i < n; i++)
	{
		if (i < n / 2)
		{
			s1.push_back(s[i]);
		}
		else
		{
			s2.push_back(s[i]);
		}
	}
	cout << (s1 == s2 ? "Yes":"No");
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll N,i,mc = 0;scanf("%lld",&N);
  ll A[N];
  for(i=0;i<N;i++){
    scanf("%lld",&A[i]);
    if(A[i] < 0) mc++;
    A[i] = abs(A[i]);
  }
  if(mc%2 == 0) printf("%lld\n",accumulate(A,A+N,0LL));
  else printf("%lld\n",accumulate(A,A+N,0LL)-*min_element(A,A+N)*2);
}

Measured memory_bytes: 4588
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

const MOD: usize = 1_000_000_007;

fn mod_pow(x: usize, n: usize, m: usize) -> usize {
    let mut ans = 1;
    let mut x = x;
    let mut n = n;
    while 0 < n {
        if n % 2 == 1 {
            ans = ans * x % m;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    ans
}

fn ncr(n: usize, r: usize, m: usize) -> usize {
    let r = std::cmp::min(r, n - r);
    let mut nu = 1;
    let mut de = 1;
    for i in 0..r {
        nu = nu * (n - i) % m;
        de = de * (i + 1) % m;
    }
    nu * mod_pow(de, m - 2, m) % m
}
fn main() {
    let (n, a, b) = get!(usize, usize, usize);
    // eprintln!("{}, {}, {}", n, a, b);
    let x = mod_pow(2, n, MOD) - 1;
    let nca = ncr(n, a, MOD);
    let ncb = ncr(n, b, MOD);
    // eprintln!("{}, {}, {}", x, nca, ncb);
    let mut ans: i64 = (x as i64 - nca as i64 - ncb as i64) % MOD as i64;
    if ans < 0 {
        ans += MOD as i64;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N;
    cin >> N;
    vector<int> A(N);
    readvec(A);

    int ans = 100000000000000;
    REP(i, N){
        int tmp = 0;
        while(A[i] % 2 == 0){
            A[i] /= 2;
            tmp++;
        }
        ans = min(ans, tmp);
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
int n,k;
int x,y,b;

int check(int y,int x,int n)
{
    if (n%2==1)
    {
        if (x>n/2+1)
        {
            x=n+1-x;
        }
        if (y>n/2+1)
        {
            y=n+1-y;
        }
        n=(n+1)/2;
        b=0;
        y-=1; x-=1;
        if (y>=x)
        {
            return (b+(x%3))%3+1;
        }else
        {
            return (b+(y%3))%3+1;
        }
    }
    else
    {
        if (x>(n/2+1))
        {
            x=n+1-x;
        }
        if (y>n/2+1)
        {
            y=n+1-y;
        }
        n=(n+1)/2;
//        cout<<x<<" "<<y<<" "<<n<<endl;
        b=0;
        y-=1; x-=1;
        if (y>=x)
        {
            return (b+(x%3))%3+1;
        }else
        {
            return (b+(y%3))%3+1;
        }

    }

}

int main()
{
    cin>>n>>k;
    for (int i=1; i<=k; ++i)
    {
        cin>>x>>y;
        cout<<check(x,y,n)<<endl;
    }
    return 0;
}




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

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    cout << h * w - a * b * (h / a) * (w / b) << endl;
}


Measured memory_bytes: 3184
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

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

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double; using vi = vector<int>;
using ll = int_fast64_t; using ull = uint_fast64_t;
using vl = vector<ll>; using vul = vector<ull>;

// -----------------------------------------------------------------------------

void solve() {
    int x; cin >> x;
    int a = x / 500; x %= 500;
    int b = x / 5; x %= 5;
    cout << 1000 * a + 5 * b << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    // preprocess();
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}


Measured memory_bytes: 256
a,b,h,m = [int(i) for i in input().split()]
 
from math import cos,radians,degrees
angle = 3.14159265358979323846264338327950 * 2.0 * (h / 12.0 + (m / 60.0) / 12.0 - m / 60.0)
print((a**2 + b**2 - 2 * a * b * cos(angle))**0.5)


Measured memory_bytes: 9420
#include<iostream>

using namespace std;

int main(){
	string S;
	string T;
	cin >> S;
	cin >> T;
	int ans;
	
	for(int i=0; i<3; i++){
		if(S[i]==T[i]){
			ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int64_t memo = 0;
      for (int k = 0; k < D; k++) {
        memo += (X.at(i).at(k) - X.at(j).at(k)) * (X.at(i).at(k) - X.at(j).at(k));
      }
      int a = sqrt(memo);
      if (sqrt(memo) == a) {
        ans++;
      }
    }
  }
  cout << ans << endl;       
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a;
  cin >>a;
  if(a == 'a'|| a == 'e'|| a == 'i'|| a == 'u'|| a == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
AC=[0]*n
WA=[0]*n
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if s=="WA":
    if AC[p]==0:
      WA[p]+=1
  else:
    AC[p]=1

ac=sum(AC)
wa=0
for i in range(n):
  if AC[i]==1:
    wa+=WA[i]
print(ac,wa)


Measured memory_bytes: 45528
import java.io.*;

class Main {
    static char calc(String str, int index) {
        char answer = str.charAt(0);

        if (str.charAt(0) == '1') {
            int lastIndex = 0;
            for (int i = 1; i < str.length(); i++) {
                if (str.charAt(i) == '1') {
                    lastIndex = i;
                } else {
                    break;
                }
            }

            if (index - 1 <= lastIndex) {
                answer = '1';
            } else {
                answer = str.charAt(lastIndex + 1);
            }
        }

        return answer;
    }

    public static void main(String args[]) throws IOException {
        String S;
        int K;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        S = br.readLine();
        String k_s = br.readLine();
        K = k_s.length() > 3 ? 101 : Integer.valueOf(k_s);

        PrintWriter pw = new PrintWriter(System.out);
        pw.println(calc(S, K));
        pw.flush();
    }
}


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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, A;
	cin >> N >> A;
	if (A >= N % 500)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

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

#define TCLOOP() int tc; cin>>tc; while(tc--)

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) int(s.length())
#define sz(v) int(v.size())
#define MOD 1000000007

// Code Here

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,b; cin>>a>>b;
    if(a > b) swap(a,b);
    if(a == 1 && b == 2) cout<<3;
    else if(a == 1 && b == 3) cout<<2;
    else cout<<1;
    return 0;
}

Measured memory_bytes: 256
<?php
while($n = trim(fgets(STDIN))) {
  $n = explode(' ', $n);
  if ($n[1] === "?") {
    break;
  } elseif ($n[1] == "+") {
    print(($n[0] + $n[2]) . "\n");
  } elseif ($n[1] == "-") {
    print(($n[0] - $n[2]) . "\n");
  } elseif ($n[1] == "*") {
    print(($n[0] * $n[2]) . "\n");
  } elseif ($n[1] == "/") {
    print(floor($n[0] / $n[2]) . "\n");
  }

}

Measured memory_bytes: 15328
n=int(input())
c=sorted(list(map(int,input().split())))
#n=200000
#c=list(range(n))
mod=pow(10,9)+7
# T=000000..とおいて計算し最後に2^nをかける。
# 各コストCiごとにそれが何回足されるかを求める。
# 一番大きいコストc[-1]の係数は必ず1にするのが最適。同様に一番小さいコストc[0]は必要な係数の中で一番大きなものをかけるのがいい。
ans=0
for i,ci in enumerate(c):
  l=i
  r=n-i
  b=pow(2,r-1,mod)+(r-1)*pow(2,r-2,mod) if r>1 else 1
  b*=pow(2,l,mod)
  ans+=ci*b
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)


Measured memory_bytes: 89164
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))

mini = min(A)
ans = min(A)
for a in A:
    amari = a % mini
    if amari != 0:
        if amari < ans:
            ans = amari            
if mini - ans == 0:
    print(ans)
else:
    print(gcd(mini, ans))

Measured memory_bytes: 16280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[110];
int main() {
	int n, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)cin >> a[i];
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			for (int k = j + 1; k < n; ++k) {
				if (a[i] == a[j] || a[j] == a[k] || a[i] == a[k])continue;
				ll sum = a[i] + a[j] + a[k];
				ll mx = max(a[i], max(a[j], a[k]));
				if (sum - mx > mx)++cnt;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    ll x;
    cin >> x;
    ll now = 100;
    for (ll i =1; i <= INF; i++) {
        now = (double) now * 1.01;
        if (now >= x) {
            cout << i << endl;
            ret();
        }
    }

}



Measured memory_bytes: 3628
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    string k;
    cin >> k;
    if (k == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3624
x,y = [int(i) for i in input().split()]
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if x in a and y in a:
  print('Yes')
elif x in b and y in b:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9052
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL P[5001],C[5001];

LL ans = -INF;

void solve(){
	//点iから行って戻ってくるまでにかかる操作回数
	vector<LL> loop(N+1);
	//点iから行って戻ってくるまでに稼げるスコア
	//もし負なら0としておく
	vector<LL> score_per_loop(N+1);
	for(int i=1;i<=N;i++){
		LL score = 0;
		LL point = i;
		LL numof_loop = 0;
		while(1){
			point = P[point];
			score += C[point];
			numof_loop++;
			if(i==point) break;
		}
		loop[i] = numof_loop;
		score_per_loop[i] = max(0LL,score);
	}

	for(int i=1;i<=N;i++){
		//各点iから初めて、0~K回操作を行った時のスコアの最大値を求める
		LL point = i;
		LL score = 0;
		for(int operation=1;operation<=min(K,loop[i]);operation++){
			point = P[point];
			score += C[point];
			ans = max(ans,score + max(0LL,((K-operation)/loop[i]))*score_per_loop[i]);
		}
	}
}
 
int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++) cin >> P[i];
	for(int i=1;i<=N;i++) cin >> C[i];
 
    solve();

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

Measured memory_bytes: 3376
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int Num = sc.nextInt();
		int cards[] = new int[Num];
		int a = 0;
		int b = 0;
		for(int n=0;n<Num;n++){
			cards[n] = sc.nextInt();
		}
		Arrays.sort(cards);

		int turn=0;
		for(int n=cards.length-1;n>=0;n--,turn++){
			if(turn%2==0) a += cards[n];
			else  b+= cards[n];
		}
		System.out.println(a-b);
	}
}

Measured memory_bytes: 23380
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
     string s;
     cin>>s;
     ll n = s.size();
     reverse(s.begin(),s.end());
     //vector<vector<ll>> dp(n,vector<ll>(2,0));
     ll dp[n+1][2];
     rep(i,n+1){rep(j,2)dp[i][j]=0;}
     dp[0][0]=1;
     dp[0][1]=0;

     for(int i=1;i<=n;i++){
         if(s[i-1]=='0'){
            // dp[i][0]=dp[i-1][0]*3;
            dp[i][0]+=dp[i-1][0];
             dp[i][0]%=MOD;
            dp[i][1]+=dp[i-1][0]*2;
            dp[i][1]%=MOD;
            dp[i][1]+=dp[i-1][1]*3;
             dp[i][1]%=MOD;

         }else {
             dp[i][0] += dp[i - 1][0] * 3;
             dp[i][0] %= MOD;

             dp[i][0] += dp[i - 1][1];
             dp[i][0] %= MOD;
             dp[i][1] += dp[i - 1][1]*2;
             dp[i][1]%=MOD;

         }
     }
     cout<<dp[n][0]<<endl;




return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    int xor_sum = 0;
    for (int x: a){
        xor_sum ^= x;
    }
    rep(i, n){
        cout << (xor_sum ^ a.at(i));
        if (i < n - 1) cout << " ";
        else cout << endl;
    }
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n;
  cin >> n;
  printf("%.3f", n * 2 * acos(-1));
  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int MAX_N = 10000;

int n;
int a[MAX_N];

// la[i][j] = num of color j "successive" in the left of i (excluding i)
int la[MAX_N][3];
int ra[MAX_N][3];

// calc num of remnants when change a[s] to c
int calcNumRem(int s, int c) {
    if (la[s][c] + 1 + ra[s][c] < 4) {
        return n;
    }

    int l = s - la[s][c];
    int r = s + ra[s][c];

    bool flag = true;
    while (flag) {
        flag = false;
        rep(j, 3) {
            if (la[l][j] + ra[r][j] >= 4) {
                l -= la[l][j];
                r += ra[r][j];
                flag = true;
                break;
            }
        }
    }

    return n - (r - l + 1);
}

void init() {
    rep(i, n) {
        a[i] = 0;
        rep(j, 3) la[i][j] = 0, ra[i][j] = 0;
    }
}

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

    while (cin >> n, n) {
        init();

        rep(i, n) {
            cin >> a[i];
            a[i]--;
        }

        rep2(i, 1, n) {
            la[i][a[i - 1]] += la[i - 1][a[i - 1]] + 1;
        }

        rrep(i, n - 1) {
            ra[i][a[i + 1]] += ra[i + 1][a[i + 1]] + 1;
        }

        int ans = n;
        rep(i, n) {
            rep(j, 3) {
                ans = min(ans, calcNumRem(i, j));
            }
        }

        cout << ans << endl;
    }

}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& oj);
};

ostream& operator<<(ostream& os, const mint& oj){
    os << oj.x;
    return os;
}

mint factorial(int n){
    mint res = 1;
for(int i=1;i<=n;++i){
        res *= i;
    }
    return res;
}

mint nCr(int n,int r){
    mint numerator = 1;
    if(r > n - r) r = n - r;
    for(int i=n;i>n-r;--i){
        numerator *= i;
    }
    mint denominator = 1;
    for(int i=1;i<=r;++i){
        denominator *= i;
    }
    return numerator/denominator;
}

int main(){
    int h,w;cin >> h >> w;
    vector<string> a(h);
    rep(i,h) cin >> a[i];

    vector<vector<mint>> dp(h+10, vector<mint>(w+10,0));
    dp[1][1] = 1;
    rep(i,h){
        rep(j,w){
            if(a[i][j] == '.') dp[i+1][j+1] += dp[i][j+1] + dp[i+1][j];
        }
    }
    /*rep(i,h+1){
        rep(j,w+1) cout << dp[i][j] << " ";
        cout << endl;
    }*/
    cout << dp[h][w] << endl;
}

Measured memory_bytes: 9344
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int D[100][6]={},count=0,z[6][7]={{1,2,4,3,1,2,4},{0,3,5,2,0,3,5},{0,1,5,4,0,1,5},{0,4,5,1,0,4,5},{0,2,5,3,0,2,5},{1,3,4,2,1,3,4}};
    for(int i=0;i<n;i++){
        cin>>D[i][0]>>D[i][1]>>D[i][2]>>D[i][3]>>D[i][4]>>D[i][5];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int a=0;
            while(1){
                if(D[j][0]==D[i][a]) break;
                a++;
                if(a==6) break;
            }
            if(a==6){
                break;
                count++;
            }
            int b=0;
            while(1){
                if(D[j][1]==D[i][b]) break;
                b++;
                if(b==6) break;
            }
            if(b==6){
                break;
                count++;
            }
            int d=0;
            while(1){
                if(D[j][2]==D[i][d]) break;
                d++;
                if(d==6) break;
            }
            if(d==6){
                break;
                count++;
            }
            int e=0;
            while(1){
                if(D[j][3]==D[i][e]) break;
                e++;
                if(e==6) break;
            }
            if(e==6){
                break;
                count++;
            }
            int f=0;
            while(1){
                if(D[j][4]==D[i][f]) break;
                f++;
                if(f==6) break;
            }
            if(f==6){
                break;
                count++;
            }
            int g=0;
            while(1){
                if(D[j][5]==D[i][g]) break;
                g++;
                if(g==6) break;
            }
            if(g==6){
                break;
                count++;
            }
            int c=0;
            while(1){
                if(z[a][c]==b) break;
                c++;
            }
            if(D[i][z[a][c+1]]==D[j][2]&&D[i][z[a][c+3]]==D[j][3]&&D[i][z[a][c+2]]==D[j][4]){
                count++;
            }
            
        }
    }
    if(count>0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
    return 0;
}


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

int n;
int ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		ans += a;
	}
	ans -= n;
	cout << ans << "\n";
}

Measured memory_bytes: 256