akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int N, D; cin >> N >> D;
    int X[N][D];
    rep(i, 0, N) {
        rep(j, 0, D) cin >> X[i][j];
    }
    int ans = 0;
    rep(i, 0, N) {
        rep(j, i+1, N) {
            int n = 0;
            rep(k, 0, D) {
                int diff = abs(X[i][k] - X[j][k]);
                n += diff * diff;
            }
            // checking condition  for pow(k, 2) == X[i][j]
            bool flag = 0;
            rep(k, 0, n+1) if (k * k == n) flag = 1;
            if (flag) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = input().split()
for i in range(n):
    w[i] = int(w[i])
k = "N"
s = sum(w)
for i in range(n-1):
    p = s-2*sum(w[:i+1])
    if p < 0:
        p = -1*p
    if k == "N":
        k = p
    elif k > p:
        k = p
print(k)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 10000000
typedef long long ll;
#define WDSIZE 10000

char S[BUFSIZE] = {0};
int N;

int main(void){
  scanf("%s",S);
  N = strlen(S);

  for(int i = 0;i < (1 + N)/2;i++){
     if (S[i] != S[N - 1 - i]){
         printf("No");
         exit(0);
       }
     }
     for(int i = 0;i < (N-1)/2;i++){
     if( S[i] != S[(N-1)/2 - 1 - i] || S[(N+1)/2 + i] != S[N - 1 - i]){
            printf("No");
            exit(0);
          }
    }
      printf("Yes");
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Class2
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            var d = str.Select(x =>int.Parse(x));
            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                for (int n = i + 1; n < N; n++)
                    ans += d.ElementAt(i) * d.ElementAt(n);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define lli long long int
#define all(x) x.begin(),x.end()
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
vector<pair<int,int> > vec;
int main()
{
	int n;
	cin>>n;
	int op=0,cl=0;
	string s;
	vector<pair<int,int> > vec1,vec2;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		pair<int,int> k={0,0};
		int cnt=0,lowest=0,low=0;
		for(int i=0;i<(int)siz(s);i++)
		{
			if(s[i]=='(')
			{cnt++;low++;continue;}
			if(cnt>0)
			{cnt--;low--;continue;}
			low--;
			lowest=min(lowest,low);
			k.second++;
		}
		k.first=cnt;
		if(k.first==0 && k.second==0)
			continue;
		if(k.second==0)
		{
			op+=k.first;
		}
		else if(k.first==0)
		{
			cl+=k.second;
		}
		else
		{
			if(k.first-k.second>=0)
			{
				vec1.push_back({-lowest,k.first-k.second});
			}
			else
			{
				vec2.push_back({lowest,k.first-k.second});
			}
		}

	}
	sort(all(vec1));
	sort(all(vec2));
	lli lw=op;
	for(auto j: vec1)
	{
		if(lw<j.first)
		{cout<<"No";return 0;}
		lw+=(lli)j.second;
	}
	for(auto j: vec2)
	{
		if(lw<-j.first)
		{cout<<"No";return 0;}
		lw+=(lli)j.second;
	}
	lw-=cl;
	if(lw!=0)
	{cout<<"No";return 0;}
	cout<<"Yes";
}



Measured memory_bytes: 5220
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <unordered_set>

using ll = long long;

int main()
{
    int K;
    std::cin >> K;

    int cnt = 0;
    for (int i = 1; i <= K; i++)
    {
        for (int j = i + 1; j <= K; j++)
        {
            if ((i + j) % 2 == 1)
            {
                cnt++;
            }
        }
    }

    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
  int i,j,k,score,count;
  int n;
  int a[200][3];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(i=0;i<n;i++){
    score=0;
    for(j=0;j<3;j++){
      count=0;
      for(k=0;k<n;k++){
	if(a[k][j]==a[i][j]){
	  count++;
	}
      }
      if(count==1){
	score+=a[i][j];
      }
    }
    printf("%d\n",score);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

unsigned int randxor() {
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t;
  t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}




int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  vector<int> last_day(26, 0);
  vector<int> t(D);
  rep(i,D) rep(j,26) cin >> s[i][j];


  int score = 0;
  int res = 0;
  auto Scoring = [&](int d, int id) {
    last_day[id] = d;
    for (int i = 0; i < 26; i++) score -= c[i] * (d - last_day[i]); 
  };

  auto init = [&](){
   for (int i = 0; i < D; i++) {
     t[i] = i % 26 + 1;
   }

  };
  
  //初期解生成 
  init();
  /*
  rep(p, 40000000) {

    int d = randxor() % D;
    int change_q = randxor() % 26;    
    int old_q = t[d];
    t[d] = change_q;
    int old_res = res;
    int old_score = score;
    Scoring(d + 1, change_q);
    if (res < old_res) {
      t[d] = old_q;
      res = old_res;
      score = old_score;
    }
  }
  */
  //cout << max(int(1e6 + score), 0) << endl;
  rep(i,D) cout << t[i] << endl;
  return 0;
} 

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, j, c[4][4] = {};
	for (i = 1; i <= 3; i++) {
		for (j = 1; j <= 3; j++) scanf("%d", &(c[i][j]));
	}
	
	int flag = 1;
	if (c[1][1] + c[2][2] != c[1][2] + c[2][1]) flag = 0;
	if (c[1][2] + c[2][3] != c[1][3] + c[2][2]) flag = 0;
	if (c[2][1] + c[3][2] != c[2][2] + c[3][1]) flag = 0;
	if (c[2][2] + c[3][3] != c[2][3] + c[3][2]) flag = 0; 
	
	if (flag == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define P 1000003

using namespace std;

typedef long long ll;

ll powmod(ll x, ll y = P - 2, ll p = P) {
	ll ans = 1;
	while(y) {
		if(y & 1) ans = ans * x % p;
		x = x * x % p;
		y >>= 1;
	}
	return ans;
}

ll Fac[P + 5], Rev[P + 5];

ll Solve() {
	ll x, d, n;
	scanf("%lld%lld%lld", &x, &d, &n);
	if(d == 0) return powmod(x, n);
	if(x == 0) return 0;
	if(n >= P) return 0;
	ll rd = powmod(d);
	x = x * rd % P;
	ll l = x, r = x + n - 1;
	if(r >= P) return 0;
	return powmod(d, n) * Fac[r] % P * Rev[l - 1] % P;
}

int main() {
	for(int i = 0; i < P; i++) Fac[i] = !i ? 1 : Fac[i - 1] * i % P, Rev[i] = powmod(Fac[i]);
	int Q;
	scanf("%d", &Q);
	while(Q--) {
		printf("%lld\n", (Solve() % P + P) % P);
	}
	return 0;
}

Measured memory_bytes: 16512
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();

        List<Long> list = new ArrayList<Long>();
        for (int i = 0; i < n; i++) {
            long a = scan.nextLong();
            list.add(a);
        }

        Collections.sort(list);//System.out.println(list);
        // listの先頭が0だったら、0を出力して即終了
        if (list.get(0) == 0) {
            System.out.println(0);
            return;
        }

        long ans = 1l;
        boolean isOver = false;
        try {
            for (int i = 0; i < n; i++) {
            long a = list.get(i);
            ans = Math.multiplyExact(ans, a);
            if (ans > 1000000000000000000l) {
                isOver = true;
                break;
            }
            } 
        } catch (ArithmeticException e) {
            isOver = true;
        }
        
        if (isOver) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        
        /*
        long ans = 1l;
        for (int i = 0; i < n; i++) {
            long a = list.get(i);
            ans *= a;
            if (ans > 1000000000000000000l || ans < 0) {
                break;
            }
        }
        if (ans > 1000000000000000000l || ans < 0) {
            //System.out.println(ans);
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        */
        
    }
}

Measured memory_bytes: 61528
#include<stdio.h>
int main(){
  int N,V=1,Vq;
  int H[20];
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  for(int i=1;i<N;i++){
    int j=0;
    Vq=1;
    while(j<i){
      if(H[i]<H[j]){
        Vq=0;
        break;
      }
      j++;
    }
    V+=Vq;
  }
  printf("%d\n",V);
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);

	return x /tmp * y;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	vector<ll> a(n);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i] /= 2;
	}
	ll hoge = a[0];

	for (int i = 0; i < n; i++)
	{
		hoge = lcm(hoge, a[i]);
		if (hoge > m) {
			cout << 0 << endl;
			return 0;
		}
	}

	bool flag = true;
	for (int i = 0; i < n; i++)
	{

		if ((hoge / a[i]) % 2 == 0) {
			flag = false;
		}
	}

	if (flag) {
		cout << (m / hoge + 1) / 2 << endl;
	}
	else
	{
		cout << 0 << endl;
	}


	return 0;
}



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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 11111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
    int n , temp  , sum = 0;
    cin >> n ;
    temp = n ;

    while(n) {
        sum+=n%10 ;
        n/=10 ;
    }
    if(temp%sum)cout << "No" << endl ;
    else cout <<"Yes" << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL a, b;
    cin >> a >> b;
    LL ans = (b +a-3) / (a-1);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	char A;
	cin >> A;
	if('A'<= A  && A<='Z'){
		cout << 'A' << endl;
	}else{
		cout << 'a' << endl;
	}
	return 0;
}


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


void solve()
{
  int n,m,k;
  cin>>n>>m>>k;
  int a[n];
  int b[m];
  long long sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i];
  }
  int j=n-1;
  for(int i=0;i<m;i++)
  {
    cin>>b[i];
    
    
  }
  int ans=0;
  for(int i=0;i<=m;i++)
  {
    while(j>=0&&sum>k)
    {
      sum-=a[j];
      j--;
    }
    if(sum>k)
      break;
    ans=max(ans,i+j+1);
    sum+=b[i];
    
  }

     
     
  
 
 
 
  cout<<ans;
  return;
}


int main()
{
solve();
}



Measured memory_bytes: 5124
S = str(input())
i = 0
error = 0

while i < len(S) and error == 0:

    if i + 5 > len(S):
        error = -1
        break

    if S[i: i + 5] == 'dream':
        i += 5
        if i + 2 <= len(S):
            if S[i: i + 2] == 'er':
                if (i + 2) == len(S):
                    i += 2
                elif S[i + 2] != 'a':
                    i += 2
    elif S[i: i + 5] == 'erase':
        i += 5
        if i + 1 <= len(S):
            if S[i] == 'r':
                if (i + 1) == len(S):
                    i += 1
                elif S[i + 1] != 'a':
                    i += 1
    else:
        error = -1
        break

if error == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 5999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)


int main() {
	int n, a[26][100] = {}, ans[26];
	string v = "";
	REP(i, 26) ans[i] = INF;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		REP(j, s.size()) a[s[j] - 'a'][i]++;
	}
	REP(i, 26) {
		REP(j, n) {
			ans[i] = min(ans[i], a[i][j]);
		}
	}
	REP(i, 26) {
		REP(j, ans[i]) {
			v.push_back(i + 'a');
		}
	}
	sort(ALL(v));
	cout << v << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
  
  string s;
  
  //最初の行
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  //画像の行
  for (int i = 0; i < h; i++) {
    cin >> s;
    cout << '#' << s << '#' << endl;
  }

  //最後の行
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 3604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <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 <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  while(true){
	int N; cin >> N; if(!N) break;
	bool is[30][30];
	fill((bool*)is, (bool*)is+30*30, false);
	REP(i,N){
	  int x, y; cin >> x >> y;
	  is[y][x] = true;
	}
	int M; cin >> M;
	int cx = 10, cy = 10, cnt = 0;
	REP(i,M){
	  char c; int d;
	  cin >> c >> d;
	  switch(c){
	  case 'N':
		for(;d>0;++cy,--d) if(is[cy][cx]){ is[cy][cx] = false; ++cnt;}
		break;
	  case 'E':
		for(;d>0;++cx,--d) if(is[cy][cx]){ is[cy][cx] = false; ++cnt;}
		break;
	  case 'S':
		for(;d>0;--cy,--d) if(is[cy][cx]){ is[cy][cx] = false; ++cnt;}
		break;
	  case 'W':
		for(;d>0;--cx,--d) if(is[cy][cx]){ is[cy][cx] = false; ++cnt;}
		break;
	  }
	  if(is[cy][cx]){ is[cy][cx] = false; ++cnt;}	  
	}
	cout << (cnt == N? "Yes": "No") << endl;
  }
  
  return 0;
}

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

char da[1010];
int n,s,e,w;

main()
{
	scanf("%s",da);
	for(int i=0;da[i];i++)
	{
		if(da[i]=='N')
		{
			n++;
		}
		else if(da[i]=='S')
		{
			s++;
		}
		else if(da[i]=='E')
		{
			e++;
		}
		else if(da[i]=='W')
		{
			w++;
		}
	}
	if((n!=0&&s!=0)||(n==0&&s==0))
	{
		if((e!=0&&w!=0)||(e==0&&w==0))
			printf("Yes");
		else
			printf("No");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 200000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int a[maxn+5];

int main()
{
    int n; scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    ll sum=0;
    rep(i,1,n) sum+=a[i];
    sum%=mod;
    sum=1ll*sum*sum%mod;
    rep(i,1,n) sum=(sum-1ll*a[i]*a[i])%mod;
    sum=(sum+mod)%mod;
    sum=1ll*(mod+1)/2*sum%mod;
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 4604
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  char str1[1000],str2[1000],str3[1000];
  scanf("%s %s",str1,str2);
  strcpy(str3,str1);
  strcat(str1,str3);
  if(strstr(str1,str2)==NULL) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 972
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int H,W,A,B;
int ans[1000][1000];

int main(){
    cin>>H>>W>>A>>B;

    for(int i=0;i<B;i++){
        for(int j=A;j<W;j++){
            ans[i][j]=1;
        }
    }
    for(int i=B;i<H;i++){
        for(int j=0;j<A;j++){
            ans[i][j]=1;
        }
    }

    rep(i,H){
        rep(j,W){
            cout<<ans[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 5120
#include<stdio.h>

int main(void)
{
	int n,b,f,r,v,count[4][3][10]={0},i,j,k,l,m;

	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&b,&f,&r,&v);
		count[b-1][f-1][r-1]+=v;
	}

	for(j=0;j<4;j++)
	{
		for(k=0;k<3;k++)
		{
			for(l=0;l<10;l++)
			{
				if(l<=9)
				{
					printf(" ");
				}
				printf("%d",count[j][k][l]);
				
			}
			printf("\n");
		}
		if(j<3)
		{
			for(m=0;m<20;m++)
			{
				printf("#");
			}
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2040
//AOJ:Daice 1 
//??????????????£?????¬?????????????????????????\?
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>

int main(){
	//nwes
	int scube[4][6]={{2,6,3,4,1,5},{3,2,6,1,5,4},{4,2,1,6,5,3},{5,1,3,4,6,2}};
	int cube[6],kcube[6];
	char sk[102];
	
	for(int i=1;i<=6;i++)	scanf("%d",&cube[i]);
	
	scanf("%s",sk);
	
	for(int i=0;i<strlen(sk);i++){

		if(sk[i]=='N'){
			for(int j=0;j<6;j++){
				kcube[j+1]=cube[scube[0][j]];
			}
			
		}else if(sk[i]=='W'){
			for(int j=0;j<6;j++){
				kcube[j+1]=cube[scube[1][j]];
			}
		}else if(sk[i]=='E'){
			for(int j=0;j<6;j++){
				kcube[j+1]=cube[scube[2][j]];
			}
		}else if(sk[i]=='S'){
			for(int j=0;j<6;j++){
				kcube[j+1]=cube[scube[3][j]];
			}
		}
		for(int j=1;j<=6;j++) cube[j]=kcube[j];
	}
	printf("%d\n",cube[1]);
	return 0;
}

Measured memory_bytes: 1188
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-27 11:55:12
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
ll mod_pow(ll x, ll n ,ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1)res = res *x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
ll invf[maxn], fac[maxn] = {1};
void fac_inv_init(int n , int p){
    for(int i = 1; i < n;i++){
        fac[i] = i * fac[i-1] % p;
    }invf[n-1] = mod_pow(fac[n-1], p-2 , p);
    for(int i = n-2; i >= 0; i--){
        invf[i] = invf[i+1] * (i+1) % p;
    }
}
ll C(ll n , ll m){
    return n < m || m < 0 ? 0 : fac[n]*invf[m]%mod*invf[n-m]%mod;
}
int32_t main()
{
    int h , w , a , b ;
    cin >> h >> w >> a >> b;
    fac_inv_init(maxn, mod);
    int ans = 0;
    for(int i = 1; i <= h-a; i++){
        //ans = (ans + C(b+i-2,i-1)*C(w+h-b-i-1,w-b-1))%mod;
       ans = (ans +  C(b+i-2,i-1)*C(w+h-b-1-i,w-1-b))% mod;
    }cout << ans << endl;
    //system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

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

using namespace std;

vector<int> checkEnable(const string& a, const string& b){
    vector<int> res(a.size()+b.size()+1, 1);
    for(int i=0;i<a.size();i++){
        bool ok = true;
        for(int j=0;j<b.size();j++){
            if(i+j >= a.size()) break;
            if(a[i+j] != '?' && b[j] != '?' && a[i+j] != b[j]) ok = false;
        }
        if(!ok) res[i] = 0;
    }
    return res;
}

int solve(const string& a, const string& b, const string&c, const vector<int>& ab, const vector<int>& ac, const vector<int>& bc){
    int res = a.size() + b.size() + c.size();
    for(int i=0;i<=a.size();i++){
        if(!ab[i]) continue;
        for(int j=i;j<=max<int>(a.size(), i+b.size());j++){
            if(!(ac[j] && bc[j-i])) continue;
            res = min(res, max<int>(a.size(), max<int>(b.size()+i, c.size()+j)));
        }
    }
    return res;
}

int main(){
    string a, b, c;
    while(cin >> a >> b >> c){
        auto ab = checkEnable(a, b);
        auto ac = checkEnable(a, c);
        auto ba = checkEnable(b, a);
        auto bc = checkEnable(b, c);
        auto ca = checkEnable(c, a);
        auto cb = checkEnable(c, b);
        int res = a.size() + b.size() + c.size();
        res = min(res, solve(a, b, c, ab, ac, bc));
        res = min(res, solve(a, c, b, ac, ab, cb));
        res = min(res, solve(b, a, c, ba, bc, ac));
        res = min(res, solve(b, c, a, bc, ba, ca));
        res = min(res, solve(c, a, b, ca, cb, ab));
        res = min(res, solve(c, b, a, cb, ca, ba));
        cout << res << endl;
    }
}

Measured memory_bytes: 384
fn main() {
    proconio::input! {
        n:usize
    }
    let mut ans = 0;
    //    let mut i = 1;
    let s = (n as f64).sqrt() as usize;
    let mut i = 1;
    while i * i <= n {
        let c = n / i;
        ans += i * c * (c + 1) / 2;
        // さらに、c について、いくつかまとめて計算。
        if c > i {
            let d = n / (i + 1);
            ans += (c * (c + 1) - d * (d + 1)) * i * (i + 1) / 4;
        }
        i += 1;
    }
    println!("{}", ans);
}


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

using namespace std;

int main(void) {
  string s[3];
  for (int i = 0; i < 3; i++) {
    cin >> s[i];
  }

  for (int i = 0; i < 3; i++) {
    printf("%c", (s[i][0] - 'a') + 'A');
  }
  cout << endl;

  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
int A[303][303];
bool B[303][303];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  rep(i, N) rep(j, N) cin >> A[i][j];

  rep(i, N) rep(j, N) rep(k, N) {
    if(A[i][j] > A[i][k]+A[k][j]) {
      cout << -1 << endl;
      return 0;
    }
    if(i == j || j == k || k == i) continue;
    B[i][j] |= (A[i][j] == A[i][k]+A[k][j]);
  }
  int ans = 0;
  rep(i, N) reps(j, i+1, N) {
    if(B[i][j]) continue;
    ans += A[i][j];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
map<LL,int> mp;
int N,K;
LL sum[SIZEN] = {0};
int main(){
    scanf("%d%d",&N,&K);
    for(int i = 1;i <= N;i++){
        scanf("%lld",&sum[i]);
        sum[i] += sum[i-1];
    }
    LL ans = 0;
    mp[0] = 1;
    int now = 0;
    for(int i = 1;i <= N;i++){
        if(i >= K)mp[sum[now++]]--;
        sum[i] -= i;
        sum[i] = (sum[i] % K + K) % K;
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >>a >>b;
    if(a < 10 && b < 10)
        cout <<a * b;
    else 
        cout <<-1;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = (int) S.size();
    long long ans = 0LL;

    for (int b = 0; b < (1 << N - 1); ++b) {
        long long tmp_sum = 0LL;
        int p_b = 0, cnt = 0;
        for (int i = 0; i < N - 1; i++) {
            cnt++;
            if (b >> i & 1) {
                tmp_sum += stoll(S.substr(p_b, cnt));
                p_b = i + 1;
                cnt = 0;
            }
        }
        ans += (tmp_sum + stoll(S.substr(p_b)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct{
  char suit;
  char value;
} Card;

void bubble(int,Card []);
void selection(int,Card []);
void isStable(int,Card [] ,Card []);

int main(){
  Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
    C2[i]=C1[i];
  }
  bubble(n,C1);
  selection(n,C2);
  isStable(n,C1,C2);
  return 0;
}

void bubble(int n,Card c1[]){
  int i,j;
  Card a;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(c1[j].value < c1[j-1].value){
	a=c1[j-1];
	c1[j-1]=c1[j];
	c1[j]=a;
      }     
    }
  }
  for(i=0;i<n;i++){
    printf("%c%c",c1[i].suit,c1[i].value);
    if(i<n-1){
      printf(" ");
    }
  }
  printf("\nStable\n");
}

void selection(int n,Card c2[]){
  int i,j,mini=0;
  Card a;
  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(c2[j].value<c2[mini].value){
	mini=j;
      }
    }
    if(c2[i].value != c2[mini].value){ 
      a=c2[i];
      c2[i]=c2[mini];
      c2[mini]=a;
    }
  }
  for(i=0;i<n;i++){
    printf("%c%c",c2[i].suit,c2[i].value);
    if(i<n-1){
      printf(" ");
    }
  }
  printf("\n");
}

void isStable(int n,Card c1[],Card c2[]){
  int i,m=0;

  for(i=0;i<n;i++){
    if(c1[i].suit==c2[i].suit){
      m++;
    } else {
      break;
    }
  }
  if(m==n){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n,0);
    vector<int> b(n,0);
    for(int i=0;i<n-1;i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i=0;i<n-1;i++){
        b[a[i]]++;
    }
    for(int i=0;i<n;i++){
        cout << b[i] << endl;
    }
}

Measured memory_bytes: 4844
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	V := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&V[i])
	}
	for i := 0; i < N; i++ {
		fmt.Scan(&C[i])
	}

	ans := 0
	for i := 0; i < N; i++ {
		x := V[i] - C[i]
		if 0 <= x {
			ans += x
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

int main(){
	long long int a, b, c;
	cin >> a >> b >> c;
	if( abs(b-c)%2==0 ){
		cout << "Alice" << endl;
	} else{
		cout << "Borys" << endl;
	}
}

Measured memory_bytes: 764
n,a,b=gets.split.map &:to_i
s=gets.chop.chars
x,y=0,0
(0...n).map{|i|
  isp=false
  if s[i]=='a'
    if x+y<a+b
      isp=true
      x+=1
    else
      isp=false
    end
  end

  if s[i]=='b'
    if x+y<a+b and y<b
      y+=1
      isp=true
    else
      isp=false
    end
  end

  isp=false if s[i]=='c'

  puts isp ? 'Yes':'No'
}


Measured memory_bytes: 10748
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
n = 0
yxyx = []

for i in range(h):
  for j in range(w):
    if i != h - 1 or j != w - 1:
      if a[i][j] % 2 != 0:
        a[i][j] -= 1
        if j == w - 1:
          a[i + 1][j] += 1
          yxyx += [i + 1, j + 1, i + 2, w]
        else:
          a[i][j + 1] += 1
          yxyx += [i + 1, j + 1, i + 1, j + 2]
        n += 1

print(n)
for i in range(n):
  print(yxyx[4 * i], yxyx[4 * i + 1], yxyx[4 * i + 2], yxyx[4 * i + 3])

Measured memory_bytes: 19596
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long MOD = (long)Math.pow(10, 9) + 7;
    int N = sc.nextInt();
    int M = sc.nextInt();
    long ans = 0;
    if(Math.abs(N - M) == 0) {
      long a = 2;
      for(long i = 1; i <= (long)N; i++) {
        a = (a * i) % MOD;
      }
      for(long i = 1; i <= (long)M; i++) {
        a = (a * i) % MOD;
      }
      ans = a;
    } else if(Math.abs(N - M) == 1) {
      long a = 1;
      for(long i = 1; i <= (long)N; i++) {
        a = (a * i) % MOD;
      }
      for(long i = 1; i <= (long)M; i++) {
        a = (a * i) % MOD;
      }
      ans = a;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(void) {
	int N, x;
	long long int ans = 0;

	cin >> N >> x;

	int a_prev = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a + a_prev > x) {
			ans += a + a_prev - x;
			a = x - a_prev;
		}
		a_prev = a;
	}

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

Measured memory_bytes: 384
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define Sort(a)	sort(a.begin(),a.end())
#define rev(a)	reverse(a.begin(),a.end())
#define all(a)	(a).begin(),(a).end()
#define vll vector<long long int>
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 200005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli power(lli a,lli b,lli m){if(b==0)	return 1;if(b==1)	return a%m;lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli Ceil(lli a,lli b){lli res=a/b;if(a%b!=0)	res++;return res;}

template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

lli dxx[]={1,1,0,-1,-1,-1,0,1};
lli dyy[]={0,1,1,1,0,-1,-1,-1};
lli dx[]={1,0,-1,0};
lli dy[]={0,1,0,-1};

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
	char ch;
	db aa,bb,cc,dd,xx;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,d,n,m,l,r,x,y,z,low,high,mid,sum=0,ans=0,temp,t;
    cin >> n;
    if(n>=30){
    	cout << "Yes";
    }
    else{
    	cout << "No";
    }
    
    
}















int main()
{
	long long int t=1,c=1;
	// scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

import sys

rectangle = []
h,w = 1,1

while not(h == 0 and w == 0):
    h,w = map(int, input().split())
    if not(h == 0 and w == 0):
        rectangle.append([h,w])

for rec in rectangle:
    row_count = 1
    display = []
    for row in range(rec[0]):
        col_count = 0
        if (row_count %2 == 1):
            col_count = 1
        else:
            col_count = 2
        for col in range(rec[1]):
            if (col_count % 2 == 1):
                display.append('#')
            else:
                display.append('.')
            col_count += 1
        row_count += 1
        display.append('\n')
    print(''.join(display))

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

int main() {

	int N;
	cin >> N;

	int T, A;
	cin >> T >> A;

	int mountains[1000];

	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		mountains[i] = h;
	}

	double min = 100000;
	int minNum = -1;
	for (int i = 0; i < N; i++) {
		if (min > abs(A - T + mountains[i] * 0.006)) {
			min = abs(A - T + mountains[i] * 0.006);
			minNum = i;
		}
	}

	cout << minNum + 1 << endl;

	return 0;

}

Measured memory_bytes: 256
import sys
line = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
for i in range(n):
    v = sys.stdin.readline().split()
    op = v[0]
    a = int(v[1])
    b = int(v[2])
    if op == "print":
        print(line[a: b + 1])
    elif op == "reverse":
        line = line[:a] + line[a: b + 1][::-1] + line[b + 1:]
    elif op == "replace":
        p = v[3]
        line = line[:a] + p + line[b + 1:]

Measured memory_bytes: 6724
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;cin >> a >> b;
    if(a>=13)cout << b;
    else if(a>=6 and a<=12)cout << b/2;
    else cout << 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int res = 0;
    for(auto& e : in) res += (e - '0');

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    int N;
    cin >> N;
    vector<string> ans;
    ans.push_back("a");
    REP(i, N-1) {
        vector<string> tmp;
        REP(j, ans.size()) {
            string s = ans[j];
            int max = 0;
            REP(k, s.size()) {
                if(s[k] - 'a' > max) max = s[k] - 'a';
            }
            REP(k, max+2) {
                string x = s;
                x += (k+'a');
                tmp.push_back(x);
            }
        }
        ans = tmp;
    }
    sort(ans.begin(), ans.end());
    REP(i, ans.size()) cout << ans[i] << endl;
}

Measured memory_bytes: 10908
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  double a,b,c,PI=3.1415926535;
  cin >> a >> b >> c;
  printf("%.5f\n",a*b*sin(c*PI/180)/2);
  printf("%.5f\n",sqrt(a*a+b*b-2*a*b*cos(c*PI/180))+a+b);
  printf("%.5f\n",b*sin(c*PI/180));
  return 0;
}



Measured memory_bytes: 3460
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[3001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, j, k, H, W, N, r[3001], c[3001];
	data d[3001];
	scanf("%d %d %d", &H, &W, &N);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &(r[i]), &(c[i]));
		d[i-1].key = r[i];
		d[i-1].id = i;
	}
	merge_sort(d, N);
	for (i = 0; i < N; i++) {
		k = d[i].key;
		for (j = i; d[j].key == k; j++) d[j].key = c[d[j].id];
		merge_sort(&(d[i]), j - i);
		i = j - 1;
	}
	
	long long fact[200001], fact_inv[200001];
	for (i = 1, fact[0] = 1; i <= H + W; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = H + W - 1, fact_inv[H+W] = div_mod(1, fact[H+W], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;

	int h, w;
	long long dp[3001], ans = fact[H+W-2] * fact_inv[H-1] % Mod * fact_inv[W-1] % Mod;
	for (i = 0; i < N; i++) {
		h = r[d[i].id];
		w = c[d[i].id];
		dp[i] = fact[h+w-2] * fact_inv[h-1] % Mod * fact_inv[w-1] % Mod;
		for (j = 0; j < i; j++) if (r[d[j].id] <= h && c[d[j].id] <= w) dp[i] = (dp[i] - dp[j] * fact[h+w-r[d[j].id]-c[d[j].id]] % Mod * fact_inv[h-r[d[j].id]] % Mod * fact_inv[w-c[d[j].id]] % Mod + Mod) % Mod;
		ans = (ans - dp[i] * fact[H+W-h-w] % Mod * fact_inv[H-h] % Mod * fact_inv[W-w] % Mod + Mod) % Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4944
// #! g++ -O3 amida_the_city_of_miracle.cpp 

#include <iostream>
#include <utility>
#include <list>
#include <algorithm>
using namespace std;

struct line{
    int number;
    int left;
    int right;
};

class lesser {
public:
    bool operator()(const struct line first, const struct line second){
        return first.number > second.number;
    }
};

int main(){

    while(1){
        int n, m, a;

        // input
        cin >> n >> m >> a;
        if( !n && !m && !a ) break;
        list<struct line> lines;
        struct line tmp;
        for(int i=0; i<m; i++){
            cin >> tmp.number >> tmp.left >> tmp.right;
            lines.push_back(tmp);
        }
        
        // initialization
        int columns[n];
        for(int i=0; i<n; i++){
            columns[i]=i+1;
        }
        lines.sort(lesser());

        // swap
        list<struct line>::iterator it;
        for(it=lines.begin(); it!=lines.end(); it++){
            int tmp                = columns[(*it).left-1 ];
            columns[(*it).left-1 ] = columns[(*it).right-1];
            columns[(*it).right-1] = tmp;
        }

        // output
        for(int i=0; i<n; i++){
            if( columns[i] == a ){
                cout << i+1 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	ll x, y;
	cin >> x >> y;
	ll a = x;
	int ans = 1;
	while (a*2 <= y)
	{
		a *= 2;
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}

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

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

	bool g = false;
	bool w = false;
	bool p = false;
	bool y = false;

	for (int i = 0; i < n; i++)
	{
		char tmp;
		cin >> tmp;

		switch (tmp)
		{
		case 'G':
			g = true;
			break;
		case 'W':
			w = true;
			break;
		case 'P':
			p = true;
			break;
		case 'Y':
			y = true;
			break;
		default:
			break;	
		}
	}

	int ans = 0;

	if (g) ans++;
	if (w) ans++;
	if (p) ans++;
	if (y) ans++;

	if (ans == 3)
	{
		cout << "Three\n";
	}
	else
	{
		cout << "Four\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 200001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char s[MAX], t[MAX];
  scanf("%s %s", s, t);

  int start[27] = {0};
  int goal[27] = {0};
  int n = strlen(s);
  int judge = 1;
  rep(i, 0, n) {
    int sc = (int)(s[i] - 'a');
    int tc = (int)(t[i] - 'a');
    if (start[sc] == 0 && goal[tc] == 0) {
      start[sc] = tc; goal[tc] = sc;
    } else {
      if (start[sc] != tc || goal[tc] != sc) {
        judge = 0;
        break;
      }
    }

  }
  if (judge) printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100100;
//#define int long long
const int INF = 1e9;

vector<int> g[MAXN];
int d[MAXN];
int blocked[MAXN];

void dfs(int v, int dh=0){
  d[v] = dh;
  for (auto i : g[v]) if (!blocked[i]) dfs(i, dh+1);
}

void solve(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i =0 ; i < n; i++){
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  if (a[0] != 0) {
    ans++;
    a[0] = 0;
  }
  for (int i = 1; i < n; i++){
    g[a[i]].eb(i);
  }

  dfs(0);

  priority_queue<pair<int, int>> q;
  for (int i = 1; i < n; i++) q.push(mp(d[i], i));

  while (!q.empty()){
    auto cur = q.top();
    int i = cur.ss;
    q.pop();

    if (d[i] <= k) continue;

    int it = 1;
    while (it < k) {
      i = a[i];
      it++;
    }

    dfs(i, 1);
    blocked[i] = 1;
    ans++;
  }

  cout << ans << '\n';

}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 15472
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
const ll MOD = 1000000007;
string v[200005];
int main(){
  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v,v+n);
  int ans=1;
  for(int i=1;i<n;i++){
    if(v[i]!=v[i-1])ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 9852