akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    cnt = -1
    res = []
    for j in range(W):
        if s[j] == 'c':
            cnt = 0
        else:
            if cnt != -1:
                cnt += 1
        res.append(cnt)
    print(*res)



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
using ld=long double;
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<ld> x(N),y(N);
  typedef pair<ld,int> P;
  for(int i=0;i<N;i++)cin>>x[i]>>y[i];
  std::vector<P> v(N);
  for(int i=0;i<N;i++)v[i]=P(atan2(y[i],x[i]),i);
  sort(v.begin(),v.end());
  ld ans=0;
  for(int i=0;i<N;i++){
    ld tx=0,ty=0;
    for(int j=0;j<N;j++){
      tx+=x[v[(i+j)%N].second];
      ty+=y[v[(i+j)%N].second];
      ans=max(ans,sqrt(tx*tx+ty*ty));
    }
  }
  cout<<fixed<<setprecision(12)<<ans<<endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll r, d, x;
  cin >> r >> d >> x;
  ll now = x;
  for (int i = 0; i < 10; i++) {
    now = r * now - d;
    cout << now << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define LLINF 110000000000000000

using namespace std;
typedef long long ll;

int main()
{
  ll N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  sort(ALL(A));

  vector<ll> Asum(A);
  REP(i, N - 1) Asum[i + 1] += Asum[i];

  ll k = -1;
  REP(i, N - 1) {
    if (2 * Asum[i] < A[i + 1]) k = i;
  }
  cout << (N - k - 1) << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  string S,T;
  cin >> S >> T;

  int tsize = T.size();

  string T2 = T.erase(tsize-1,1);

  if(T2 == S){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x[51],y[51];
	for (int i=0;i<n;i++) cin>>x[i]>>y[i];
	map<pair<int,int>,int>::iterator it;
	map<pair<int,int>,int> mp;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++){
			int dx=x[i]-x[j];
			int dy=y[i]-y[j];
			if (dx || dy) mp[make_pair(dx,dy)]++;
		}
	int mx=0;
	for (it=mp.begin();it!=mp.end();it++)
		mx=max(mx,it->second);
	printf("%d\n",n-mx);
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int cnt = 0;

template <typename It>
void merge(It l, It m, It r) {
	vector<int> tmp(r - l);
	It it = tmp.begin(), it1 = l, it2 = m;
	while (it1 != m && it2 != r) {
		cnt++;
		if (*it1 < *it2)
			*it++ = *it1++;
		else
			*it++ = *it2++;
	}
	while (it1 != m) { *it++ = *it1++; cnt++; }
	while (it2 != r) { *it++ = *it2++; cnt++; }
	copy(tmp.begin(), tmp.end(), l);
};

template <typename It>
void merge_sort(It l, It r) {
	if (r - l <= 1)return;
	It m = l + (r - l) / 2;
	merge_sort(l, m);
	merge_sort(m, r);
	merge(l, m, r);
}

signed main() {
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	merge_sort(v.begin(), v.end());
	cout << v[0]; rep(i, 1, v.size()) { cout << " " << v[i]; } cout << endl;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7716
//file_name:ABC59_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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



    cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int s, cnt;
    cin >> s;
    cnt = 0;

    if (s % 10 == 1){
      cnt += 1;
    }
    if (s / 10 % 10 == 1){
      cnt += 1;
    }
    if (s / 100 == 1){
      cnt += 1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split() ))

maximum = (n-1)*(n-2)//2
if(k <= maximum):
	#構成可能
	ans = n - 1 + maximum -k
	print(ans)
	# 頂点1と残りの頂点をつなぐ
	for i in range(2, n + 1):
		print("{} {}".format(1 ,i)	)

	# 頂点2以上のなかで、maximus - k 個をつなぐ
	count = n-1
	if count == ans:
		exit()
	i = 2
	j = 3
	while True:
		print("{} {}".format(i ,j)	)
		count += 1
		if count == ans:
			break
		j += 1
		if j > n:
			i += 1
			j = i+1

else:
	print(-1)


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,M,ans;
int main(){
  	cin>>N>>M;
    if(N>=M/2){
        cout<<M/2<<"\n";
        return 0;
    }
    cout<<(M+2*N)/4<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a[30], b[30], n, max = 0, atai = 0;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 1; i <= 26; i++) {a[i] = 0; b[i] = 0;}
    
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j <= i; j++) {
            a[s[j] - 'a' + 1]++;
        }
        for (int j = i + 1; j < n; j++) {
            b[s[j] - 'a' + 1]++;
        }
        for (int j = 1; j <= 26; j++) {
            if (a[j] > 0 && b[j] > 0) atai++;
        }
        if (atai > max) max = atai;
        for (int j = 1; j <= 26; j++) {a[j] = 0; b[j] = 0;}
        atai = 0;
    }
    
    cout << max;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int h,w,s;
	char a[100][100];
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		cin>>a[i][j];
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(a[i][j]=='#')cout<<a[i][j];
			else
			{
				s=0;
				for(int p=-1;p<=1;p++)
					for(int q=-1;q<=1;q++)
					if(a[p+i][q+j]=='#')s++;
				cout<<s;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include<algorithm>
using namespace std;

int main(void)
{
	string str;
	unsigned long long x, y, ans = 0;
	int num = 0;

	cin >> x >> y;
	
	while (ans < y){
		if (num == 0){
			ans = x;
			if (ans > y) break;
		}
		else{
			ans *= 2;
			if (ans > y) break;
		}
		num++;
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
char a[52][52],b[52][52];
set<tuple<int,int,int,int>> dp;
int ans;

void calc(int lx,int ly,int rx,int ry){
  queue<tuple<int,int,int,int>> Q;
  Q.push(make_tuple(lx,ly,rx,ry));
  while(!Q.empty()){
    lx=get<0>(Q.front());
    ly=get<1>(Q.front());
    rx=get<2>(Q.front());
    ry=get<3>(Q.front());
    Q.pop();
    if(a[lx][ly]=='%'&&b[rx][ry]=='%'){
      ans=1;
      return;
    }
    else if(a[lx][ly]=='%'||b[rx][ry]=='%') continue;
    tuple<int,int,int,int> now;
    now=make_tuple(lx,ly,rx,ry);
    decltype(dp)::iterator it =dp.find(now);
    if(it!=dp.end()) continue;
    dp.insert(now);
    int nxl=lx,nyl=ly,nxr=rx,nyr=ry;
    if(a[lx+1][ly]!='#') nxl++;
    if(b[rx-1][ry]!='#') nxr--;   
    Q.push(make_tuple(nxl,nyl,nxr,nyr));
    nxl=lx;nyl=ly;nxr=rx;nyr=ry;
    if(a[lx-1][ly]!='#') nxl--;
    if(b[rx+1][ry]!='#') nxr++;
    Q.push(make_tuple(nxl,nyl,nxr,nyr));
    nxl=lx;nyl=ly;nxr=rx;nyr=ry;
    if(a[lx][ly+1]!='#') nyl++;
    if(b[rx][ry+1]!='#') nyr++;
    Q.push(make_tuple(nxl,nyl,nxr,nyr));
    nxl=lx;nyl=ly;nxr=rx;nyr=ry;
    if(a[lx][ly-1]!='#') nyl--;
    if(b[rx][ry-1]!='#') nyr--; 
    Q.push(make_tuple(nxl,nyl,nxr,nyr));
  }
  return;
}

int main(){
  while(1){
    int w,h;
    cin>>w>>h;
    int stxl,styl,stxr,styr;
    if(w==0&&h==0) break;
    lp(i,52){
      lp(j,52){
	a[i][j]='#';
	b[i][j]='#';
      }
    }
    lp(i,h+1){
      if(i==0) continue;
      lp(j,w+1){
	if(j==0) continue;
	cin>>a[j][i];
	if(a[j][i]=='L'){
	  stxl=j;
	  styl=i;
	}
      }
      lp(j,w+1){
	if(j==0) continue;
	cin>>b[j][i];
	if(b[j][i]=='R'){
	  stxr=j;
	  styr=i;
	}
      }
    }
    dp.clear();
    ans=0;
    calc(stxl,styl,stxr,styr);
    if(ans==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
  return 0;
}



Measured memory_bytes: 109964
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    char S[3];
    cin >> S;

    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[0]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
def my_prime(n:int):
    if n <= 1:
        return {}
    fac = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            fac.append(i)
    if temp!=1:
        fac.append(temp)
    if fac==[]:
        fac.append(n)
    return fac
n = int(input())
temp = n
cnt = 0
for x in my_prime(n):
    i=1
    while x**i <= n:
        if temp % x**i == 0:
            cnt += 1
            temp = temp // x**i
        i += 1
print(cnt)

Measured memory_bytes: 9480
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int N=in.nextInt();int i,j,f=0;
    int M=in.nextInt();
    for(i=1;i<=N;i++)
    {
      for(j=i+1;j<=N;j++)
        f++;
    }
    for(i=1;i<=M;i++)
    {
      for(j=i+1;j<=M;j++)
        f++;
    }
    System.out.println(f);
  }
}
      
    

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
struct val
{
    int a,b,c;
};
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,w;
cin>>n>>w;
pair<int,int> arr[n];
for(int i=0;i<n;i++)
{
    cin>>arr[i].ff>>arr[i].ss;
}
int dp[w+1]={};
int prev[w+1]={};
prev[0]=arr[0].ss;

for(int i=1;i<=w;i++)
{
    if(i>=arr[0].ff)
    {
        prev[i]=max(prev[i-1],prev[i-arr[0].ff]);
    }

}


prev[0]=0;
for(int i=1;i<n;i++)
{

   for(int j=1;j<=w;j++)
   {if(j>arr[i].ff)
   {
       dp[j]=max(prev[j-arr[i].ff]+arr[i].ss,prev[j]);
       dp[j]=max(dp[j-1],dp[j]);
   }
   else if(j==arr[i].ff)
   {
       dp[j]=max(arr[i].ss,prev[j]);
   }
   else
    dp[j]=max(dp[j],prev[j]);
   }
   for(int j=0;j<=w;j++)
   {prev[j]=dp[j];

   dp[j]=0;
   }
   cout<<endl;
}
cout<<prev[w]<<endl;







    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isp[1000000]={};


void makeEra(){
    for(int i=2;i<=1000;i++){
        if( isp[i] ){
            for(int j=2;j<=1000000/i;j++){
                isp[i*j]=false;
            }
        }
    }
}


int main(){
    rep(i,1000000)isp[i]=true;
    isp[0]=isp[1]=false;
    makeEra();
    
    int n;
    while(cin>>n){
        if(n==0)break;
        int c=0;
        int sum=0;
        for(int i=0;;i++){
            if(isp[i]){
                c++;
                sum+=i;
            }
            if( c==n )break;
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 2136
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


//initialization here
//
int n, ma, mb;
int a[50], b[50], c[50];
int dp[50];
//
//initialization finish


// your function is here
//

//
// your function finished



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

	// your code is here
	//

	string s; cin >> s;
	ll a=INF, b=0;
	rep(i, s.length())
	{
		if (s[i] == 'A'&&a == INF) a = i;
		if (s[i] == 'Z'&&a!=INF) b = i;
	}

	Print(b - a+1);

	//
	// your code finished
	return 0;
}

Measured memory_bytes: 720
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

def main():
    count = 0
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j] & 1:
                ans.append([i+1, j+1, i+1, j+2])
                a[i][j+1] += 1
                count += 1

    for i in range(H-1):
        if a[i][W-1] & 1:
            ans.append([i+1, W, i+2, W])
            a[i+1][W-1] += 1
            count += 1

    print(count)
    [print(*a) for a in ans]

if __name__ == "__main__":
    main()


Measured memory_bytes: 33564
#include <iostream>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	
	bool isYes = false;
	for (int i = 0; i <= N / 4; i++)
	{
		for (int j = 0; j <= N / 7; j++)
		{
			// 1個 4ドルのケーキと 1個 7ドルのドーナツ
			if (i * 4 + j * 7 == N)
			{
				isYes = true;
				break;
			}
		}
	}
	
	if (isYes == true)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

void print(char c, int n){
    for(int i=0;i<n;i++){
        cout << c;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx-sx;
    int dy = ty-sy;
    print('U', dy);print('R', dx);
    print('D', dy);print('L', dx);
    print('L', 1);print('U', dy+1);print('R', dx+1);print('D', 1);
    print('R', 1);print('D', dy+1);print('L', dx+1);print('U', 1);
    cout << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;

int main()
{
	vector<bool> v;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int h;
		cin >> h;
		v.push_back((i + 1) == h);
	}

	int Ans = 0;
	int count_ = 0;
	for (int i = 0; i < N; i++)
	{
		if (v[i])count_++;
		else
		{
			if (count_ % 2 == 1)
			{
				Ans += count_ / 2 + 1;
			}
			else
			{
				Ans += count_ / 2;
			}
			count_ = 0;
		}
	}
	if (count_ % 2 == 1)
	{
		Ans += count_ / 2 + 1;
	}
	else
	{
		Ans += count_ / 2;
	}
	cout << Ans << endl;
	return 0;
}

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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for (int& x : a)
        cin >> x;
    double sum = 0;
    long long ss = 0;
    for (int x : a)
        sum += x, ss += x;
    sum /= 2;
    long long mn = INF;
    double s = 0;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        s += a[i];
        if (abs(s - sum) < mn) {
            mn = abs(s - sum);
            ans = s;
        }
    }
    long long y = ss - ans;
    long long a1 = max(ans, y);
    long long a2 = min(ans, y);
    cout << a1 - a2;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n, k;
    cin >> n >> k;
    int prod = 1;
    int cnt=0;
    while(true){
        prod *= k;
        cnt++;
        if(prod>n) break;
    }
    
    cout << cnt << endl;
    // printf("%d\n", N);
    return 0;
}

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

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll c[10][10]={};

ll ltmp;
string stmp;
double dtmp;
ll H,W;
ll countans = 0;

ll getsum(vll masu){

    vll wsousa,hsousa;
    rep(wi,W){
        wsousa.push_back(masu[wi]);
    }
    rep(hi,H){
        hsousa.push_back(masu[hi+W]);
    }

    ll sum0 = 0;
    rep(hi,H){
        rep(wi,W){
            if(hsousa[hi]==0&&wsousa[wi]==0){
                sum0+=c[hi][wi];
            }
        }
    }
    return sum0;
}

void counting(vll masu,ll index){
    if(index==H+W){
        ll total = getsum(masu);
        if(total == K) countans++;

    }else{
        masu.push_back(0);
        counting(masu,index+1);
        masu[index] = 1;
        counting(masu,index+1);
    }

}


int main(){

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

    cin >> H;
    cin >> W;
    cin >> K;

    
    string S;
    rep(hi,H){
        cin >> S;
        rep(wi,S.size()){
            stmp = S.substr(wi,1);
            if(stmp == "#") c[hi][wi] = 1;
        }
    }

    vll masu;
    counting(masu,0);

    cout << countans << endl;


    



}

Measured memory_bytes: 3664
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

constexpr LL mod = 1e9 + 7;

int main() {

    int N;
    cin >> N;

    string S;
    cin >> S;

    for (int i = 0; i < 2 * N; i += 2) {
        if (S[i] == 'B') S[i] = 'W';
        else S[i] = 'B';
    }

    LL ans = 1;
    LL W = 0;
    LL B = 0;

    for (int i = 0; i < 2 * N; i++) {
        if (S[i] == 'B') {
            if(W == 0){
                cout << 0 << endl;
                return 0;
            }
            ans *= W;
            W--;
            ans %= mod;
        } else {
            W++;
        }
    }

    if(W > 0){
        cout << 0 << endl;
        return 0;
    }

    for (LL i = 1; i <= N; i++) {
        ans *= i;
        ans %= mod;
    }

    cout << ans << endl;

}






























































Measured memory_bytes: 640
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N) {
		string ans = "No";
		REP(i, N) {
			if((N-i*7)%4==0 && (N-i*7)/4 >= 0) ans="Yes";
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
vector<pair<int,int> > G[maxn];
int Ans[maxn];
void dfs(int u,int fa,int sum)
{
  //cout<<u<<"  " << sum<<endl;
  if(sum & 1) Ans[u] = Ans[0]^1;
  else Ans[u] = Ans[0];
  for(auto i : G[u])
  {
    int v = i.first , w = i.second;
    if(v == fa) continue;
    dfs(v,u,sum+w);
  }
}
int main()
{
  int n;
  scanf("%d",&n);
  for(int i = 0 ; i < n - 1 ; i ++)
  {
    int u,v,w;scanf("%d%d%d",&u,&v,&w);
    G[u].emplace_back(v,w);
    G[v].emplace_back(u,w);
  }
  //puts("----");
  Ans[0] = 0;
  dfs(1,0,0);
  for(int i = 1 ; i <= n ; i++) cout<<Ans[i]<<" ";puts("");
}

Measured memory_bytes: 8320
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {

r#"2 2919"# => r#"3719"#,

r#"22 3051"# => r#"3051"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize, r: usize,
    }

    (100 * (10 - if n < 10 { n } else { 10 }) + r).to_string()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include<string>
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
	ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=(n);j+=i){
			sum+=j;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3592
checkA :: String -> Bool
checkA ('>':'\'':sls) = sLength /= 0 && tilda srest sLength
  where
    (sLength, srest) = sharp sls
    sharp :: String -> (Int, String)
    sharp ('#':sr) = (0, sr)
    sharp ('=':sr) = (i + 1, s)
      where
        (i, s) = sharp sr
    sharp _ = (0, [])
    tilda :: String -> Int -> Bool
    tilda ['~'] 0 = True
    tilda ('=':sr) i = tilda sr (i - 1)
    tilda _ _ = False
checkA _ = False

checkB :: String -> Bool
checkB ('>':'^':'Q':sr) = f ('Q':sr) == "~~"
  where
    f :: String -> String
    f ('Q':'=':s) = f s
    f s = s
checkB _ = False

distinction :: String -> String
distinction s
  |checkA s = "A"
  |checkB s = "B"
  |otherwise = "NA"

main :: IO ()
main = do
  arg <- fmap lines getContents
  mapM_ (putStrLn . distinction) (tail arg)

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            final int n = scanner.nextInt();
            final int m = scanner.nextInt();
            if (n == 0 && m == 0) {
                break;
            }
            final int[][] data = new int[n][2];
            for (int i = 0; i < n; i++) {
                data[i][0] = scanner.nextInt();
                data[i][1] = scanner.nextInt();
            }
            Arrays.sort(data, new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o1[1] == o2[1] ? 0 : (o1[1] < o2[1] ? 1 : -1);
                }
            });
            int result = 0;
            int i = 0;
            for (int sum = 0; i < n; i++) {
                if (sum + data[i][0] > m) {
                    result += (sum + data[i][0] - m) * data[i][1];
                    break;
                } else {
                    sum += data[i][0];
                }
            }
            for (i++ ; i < n; i++) {
                result += data[i][0] * data[i][1];
            }
            System.out.println(result);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 0
while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
                break
        countH, countW = 0, 0
        while True:
                if countH == H:
                        break
                if countH == 0 or countH == H - 1:
 
                        while True:
                                if countW == W:
                                        print('')
                                        break
                                print('#',end='')
                                countW += 1
                else:
                        print('#',end='')
                        while True:
                                if countW == W - 2:
                                        break
                                print('.',end='')
                                countW += 1
                        print('#')
                countW = 0
                countH += 1
        print('')

Measured memory_bytes: 9128
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] Ai = new int[N];
   for(int i = 0;i<N;i++) Ai[i] = sc.nextInt()-(i+1); 
   Arrays.sort(Ai);
   long sum =0;
   int b ;
   long min ;
   if(N%2==1)
   {
     b = Ai[N/2];
     for(int i = 0;i<N;i++)
     {
       sum+=Math.abs(Ai[i]-b);
     }
     min = sum;
   }
   else
   {
     b = Ai[N/2];
     for(int i = 0;i<N;i++)
     {
       sum+=Math.abs(Ai[i]-b);
     }
     min = sum;
     b = Ai[(N/2)-1];
     for(int i = 0;i<N;i++)
     {
       sum+=Math.abs(Ai[i]-b);
     }
     if(min>sum) min = sum;
   }  
   System.out.println(min);
 }
}

Measured memory_bytes: 86520
def main(S, T):
    N = len(S)
    ans = 0
    for i in range(N//2):
        if S[i] != T[i]:
            ans += 1
        if S[-1-i] != T[-1-i]:
            ans += 1
    if N%2 == 1:
        if S[N//2] != T[N//2]:
            ans += 1
    return ans

if __name__ == '__main__':
    S = input()
    T = input()
    ans = main(S, T)
    print(ans)



Measured memory_bytes: 9392
#include <iostream>

using namespace std;

int main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	
	int count = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i] && a[i] != c[i])
			++count;
		
		if (b[i] != c[i])
			++count;
	}
	
	cout << count << endl;
}

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

int main() {
    set<int> s;
    for (int i = 0; i < 3; ++i) s.insert(i + 1);
    for (int i = 0; i < 2; ++i) {
        int x;  cin >> x;
        s.erase(x);
    }
    cout << *s.begin() << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,j;
  char a[6];
  gets(a);
  j=0;
  for(i=2;i<6;i++)
  {		if(a[i]==a[i+1])
    	j++;
  }
  if(j>1)
    printf("Yes");
  else
    printf("No");
}

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

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

    vector<int> ans(n+1);

    for(int x=1; x < sqrt(n); x++)
    {
        for(int y=1; y < sqrt(n); y++)
        {
            for(int z=1; z < sqrt(n); z++)
            {
                int e = x*x + y*y + z*z + x*y + y*z + z*x;
                if (e <= n){
                    ans[e]++;  
                }
            }
        }
    }


    for(int i =1; i<n+1; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <stdio.h>
using namespace std;

#define NELEMS(array) (sizeof(array) / sizeof(array[0]))

int abs(int a) {
	if(a < 0)
		return -a;
	else 
		return a;
}

int main(void)
{
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x - a) >= abs(x - b))
		cout << "B" << endl;
	else
		cout << "A" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
char s[1007];
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>s;
	int l=strlen(s);
	if(s[l-1]=='s') cout << s << "es\n";
	else cout << s << "s\n";
}


Measured memory_bytes: 3616
#include <cstdio>

#define N 10000

typedef long long int lli;

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i*N + j] += a[i*N + k] * b[k*N + j];
}

int main(void) {
    scanf("%d%d%d",&n,&m,&l);

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            scanf("%lld", &a[i*N + j]);
    for(int i=0; i<m; i++)
        for(int j=0; j<l; j++)
            scanf("%lld", &b[i*N + j]);
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            c[i*N + j] = 0;

    mult();

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 27780
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

score = 0
item = float('inf')
for a in A:
    score += B[a-1]
    if item+1 == a:
        score += C[a-2]
    item = a
print(score)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
    char mat[1000][10000]; 
    int n=0, i, j, sum;
    
    while(1){
        scanf("%s", mat[n]);
        if(mat[n][0]=='0') break;
        n++;
    }
    
    for(i=0; i<n; i++){
        j=0, sum=0;
        while(mat[i][j]){
            sum+=mat[i][j]-'0';
            j++;
        }
        printf("%d\n", sum);
    }
    
    return 0;
}


Measured memory_bytes: 2232
#include<stdio.h>

#define NUMBER 10

int main()
{
    int height[NUMBER];
    int i, tmp;

    for(i = 0; i < NUMBER; ++i)
      scanf("%d", &height[i]);

    for(i = 0; i < NUMBER-1; ++i) {
      for(int j = NUMBER-1; j > i; --j){
        if(height[j] > height[j-1]) {
          tmp = height[j];
          height[j] = height[j-1];
          height[j-1] = tmp;
        }
      }
    }

    for(i = 0; i < 3; ++i)
      printf("%d\n", height[i]);

    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
map<int, int> mp;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(n, 0)), b(n, vector<int>(n, 0));
	string tmp;
	rep(i, n) {
		cin >> tmp;
		rep(j, n) {
			if (tmp[j] == '.')	a[i][j] = 0;
			else a[i][j] = 1;
		}
	}
	rep(i, m) {
		cin >> tmp;
		rep(j, m) {
			if (tmp[j] == '.')	b[i][j] = 0;
			else b[i][j] = 1;
		}
	}
	bool ans = true;
	for (int i = 0; i <= n - m; ++i) {
		for (int j = 0; j <= n - m; ++j) {
			ans = true;
			rep(k, m) {
				rep(l, m) {
					if (a[i + k][j + l] != b[k][l])	ans = false;
					if (!ans)	break;
				}
				if (!ans)	break;
			}
			if (ans) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3588
while True:
    m,f,r=map(int,input().split())
    if (m==-1 and f==-1 and r==-1):
        break
    elif(m==-1 or f==-1):
        print("F")
    elif (m+f>=80):
        print("A")
    elif (65<=m+f<80):
        print("B")
    elif (50<=m+f<65):
        print("C")
    elif (30<=m+f<50):
        if (r>=50):
            print("C")
        elif (r<50):
            print("D")
    else:
        print("F")


Measured memory_bytes: 5592
def main():
    import sys
    input = sys.stdin.readline

    mod = 10**9+7
    N = int(input())
    C = list(map(int, input().split()))

    C.sort()
    ans = 0
    for i, c in enumerate(C):
        #print(ans)
        a = N - i - 1
        if a != 0:
            ans = (ans + (c * pow(2, i, mod))%mod * (pow(2, a-1, mod) * (a+2))%mod) % mod
        else:
            ans = (ans + (c * pow(2, N-1, mod))%mod) % mod
    print((ans * pow(2, N, mod))%mod)


if __name__ == '__main__':
    main()


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

int main(){
 
  int a,b;
  scanf("%d %d",&a,&b);
  
  if(b==100){
    a=1000*a;
  }else if(b>=10){
    a=100*a;
  }else{
    a=10*a;
  }
  
  int c=sqrt(a+b);
  if(c*c==a+b){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int n,s,i,j,temp,sum = 0;

    scanf("%d %d", &n, &s);

    int a[n];

    for(i = 0; i < n ; i++)
    {
        scanf("%d", &a[i]);
    }
    for(i = 0; i < n-1; i++)
    {
        for(j = i+1; j < n; j++)
        {
            if(a[i]<a[j])
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    for(i = 0; i < s; i++)
    {
        sum+=a[i];
    }

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

    return 0;
}



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

int main()
{
	int n[4];

	cin >> n[0] >> n[1] >> n[2] >> n[3];
	sort(n, n + 4);

	if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
hsh1,hsh2 = [0]*26,[0]*26

hsh1[ord(s[0])-97]+=1
for i in range(1,n):
    hsh2[ord(s[i])-97]+=1
ans=0
ct=0
for i in range(26):
    if(hsh1[i]!=0 and hsh2[i]!=0):
        ct+=1
ans = max(ans,ct)

for i in range(1,n-1):
    ct=0
    cur = ord(s[i])-97
    hsh2[cur]-=1
    hsh1[cur]+=1
    for j in range(26):
        if(hsh1[j]!=0 and hsh2[j]!=0):
            ct+=1
    ans = max(ans,ct)
print(ans)


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

void bit_init(int n);
int bit_sum(int n);
void bit_add(int n,int v);

int BIT[10000010],bit_size;

int main(){
  int n,q;
  cin >>n >>q;

  bit_init(n);
  int com,x,y;
  for(int i=0;i<q;i++){
    cin >> com >> x >> y;
    if(com==0){bit_add(x,y);
    }    else{
      cout << bit_sum(y)-bit_sum(x-1) << endl;
    }
  }
  
}

void bit_init(int n){
  fill(BIT,BIT+n,0);
  bit_size =n;
}

int bit_sum(int n){
  int ans=0;
  while(n>0){
    ans += BIT[n];
    n &= n-1;
  }
  return ans;
}

void bit_add(int n,int v){
  while(n <= bit_size){
    BIT[n]+=v;
    n += n & (-n);
  }
}

Measured memory_bytes: 1548
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    
    if(a == 1){
        if(b == 2){
            cout << 3;
        }else{
            cout << 2;
        }
    }
    if(a == 2){
        if(b == 1){
            cout << 3;
        }else{
            cout << 1;
        }
    }
    if(a == 3){
        if(b == 1){
            cout << 2;
        }else{
            cout << 1;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

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

	Int N;
	cin >> N;

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

	vector<Int> dp(N + 1);
	dp[0] = 0;

	for (Int i = 0; i < N; i++) {
		dp[i + 1] = dp[i] + a[i];
	}

	Int ans = INF;
	Int su, ar;
	for (Int i = 0; i < N-1; i++) {
		su = dp[i + 1];
		ar = dp[N] - dp[i + 1];
		ans = min(ans, abs(su - ar));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

int main() {

	int N;
	string S;
	
	cin >> N;
	cin >> S;

	if (N >= S.size())
	{
		cout << S;
	}
	else
	{
		cout << S.erase(N) << "...";
	}

	return 0;
	
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    A = [list(input()[:-1]) for _ in range(H)]

    B = [0]*H
    C = [0]*W
    for i in range(H):
        for j in range(W):
            if A[i][j]==".":
                B[i] += 1
                C[j] += 1
    
    ans = ""
    for i in range(H):
        if B[i]==W:
            continue
        for j in range(W):
            if C[j]==H:
                continue
            ans += A[i][j]
        ans += "\n"

    print(ans[:-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

void dfs(int idx, int parent, int cur, const vector<vi> &g, vector<int> &d) {
  d[idx] = cur;
  for (const auto v : g[idx]) {
    if (v == parent)
      continue;
    dfs(v, idx, cur + 1, g, d);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vi> g(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vi d(n, 0);
  dfs(0, -1, 0, g, d);
  int l = 0, r = 0;
  REP(i, n) {
    if (d[i] % 2 == 0) {
      l++;
    } else {
      r++;
    }
  }

  vi ans(n);
  // 1,2を均等に振る場合
  if (l > n / 3 && r > n / 3) {
    int c0 = 1, c1 = 0, c2 = 0;
    REP(i, n) {
      if (d[i] % 2 == 0) {
        if (c1 * 3 + 1 <= n) {
          ans[i] = c1 * 3 + 1;
          c1++;
        } else {
          ans[i] = c0 * 3;
          c0++;
        }
      }
    }
    REP(i, n) {
      if (d[i] % 2 == 1) {
        if (c2 * 3 + 2 <= n) {
          ans[i] = c2 * 3 + 2;
          c2++;
        } else {
          ans[i] = c0 * 3;
          c0++;
        }
      }
    }
  }

  // 片側に0を寄せる場合
  if (l <= n / 3) {
    vector<bool> used(n + 1, false);
    int c0 = 1, c1 = 0, c2 = 0;
    REP(i, n) {
      if (d[i] % 2 == 0) {
        ans[i] = c0 * 3;
        used[c0 * 3] = true;
        c0++;
      }
    }

    REP(i, n) {
      if (d[i] % 2 == 1) {
        if (c0 * 3 <= n && !used[c0 * 3]) {
          ans[i] = c0 * 3;
          used[c0 * 3] = true;
          c0++;
          continue;
        }
        if (c1 * 3 + 1 <= n && !used[c1 * 3 + 1]) {
          ans[i] = c1 * 3 + 1;
          used[c1 * 3 + 1] = true;
          c1++;
          continue;
        }
        if (c2 * 3 + 2 <= n && !used[c2 * 3 + 2]) {
          ans[i] = c2 * 3 + 2;
          used[c2 * 3 + 2] = true;
          c2++;
          continue;
        }
      }
    }
  }
  // 片側に0を寄せる場合
  if (r <= n / 3) {
    vector<bool> used(n + 1, false);
    int c0 = 1, c1 = 0, c2 = 0;
    REP(i, n) {
      if (d[i] % 2 == 1) {
        ans[i] = c0 * 3;
        used[c0 * 3] = true;
        c0++;
      }
    }

    REP(i, n) {
      if (d[i] % 2 == 0) {
        if (c0 * 3 <= n && !used[c0 * 3]) {
          ans[i] = c0 * 3;
          used[c0 * 3] = true;
          c0++;
          continue;
        }
        if (c1 * 3 + 1 <= n && !used[c1 * 3 + 1]) {
          ans[i] = c1 * 3 + 1;
          used[c1 * 3 + 1] = true;
          c1++;
          continue;
        }
        if (c2 * 3 + 2 <= n && !used[c2 * 3 + 2]) {
          ans[i] = c2 * 3 + 2;
          used[c2 * 3 + 2] = true;
          c2++;
          continue;
        }
      }
    }
  }

  REP(i, n) {
    cout << ans[i];
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << "\n";
    }
  }

  return 0;
}


Measured memory_bytes: 22656
#include <stdio.h>

#define MAX_H 250

struct Node{
  int id; //node id
  int k; // node key
  int pk; //parent node key
  int lk; //left node key
  int rk; //right node key
};

int main (void)
{
  int i,h;
  struct Node a[MAX_H + 1];

  scanf ("%d",&h);
  if (h <= MAX_H)
    for (i = 1 ; i < h+1 ; i++){
      scanf ("%d",&a[i].k);
    }

  for (i = 1 ; i < h+1 ; i++){
    a[i].id = i;
    if (i != 1)
      a[i].pk = i / 2;
    if (h >= i * 2)
      a[i].lk = i * 2;
    if (h >= i * 2 + 1)
      a[i].rk = i * 2 + 1;
  }

  for (i = 1 ; i < h+1 ; i++){
    printf ("node %d: key = %d, ",a[i].id,a[i].k);
    if (i != 1)
      printf ("parent key = %d, ",a[a[i].pk].k);
    if (h >= i * 2)
      printf ("left key = %d, ",a[a[i].lk].k);
    if (h >= i * 2 + 1)
      printf ("right key = %d, ",a[a[i].rk].k);
    printf ("\n");
  }

  return 0;
}

Measured memory_bytes: 604