akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define ABS(a) ((a)>(0)?(a):-(a))
#define POS(i,j,k) (((i)*2+(j))*(m+1)+ABS(k))

void init(int *a,int n){
  int i;
  for(i=0;i<n;i++) a[i]=0;
  return;
}

void run(void){
  const int m=8000;
  char *s=(char *)malloc(sizeof(char)*(m+1));
  scanf("%s",s);
  int len=0;
  while(s[len]!='\0') len++;
  int x,y;
  scanf("%d%d",&x,&y);
  int i;
  for(i=0;i<len && s[i]=='F';i++,x--);
  int *dp=(int *)calloc(2*2*(m+1),sizeof(int));
  dp[POS(0,0,0)]=1;
  dp[POS(1,0,0)]=1;
  int now[2]={0,0};
  int dir=0;
  while(i<len){
    while(i<len && s[i]=='T'){
      dir^=1;
      i++;
    }
    int k=0;
    while(i<len && s[i]=='F'){
      k++;
      i++;
    }
    init(dp+POS(dir,now[dir]^1,0),m+1);
    int next=now[dir]^1;
    int j;
    for(j=0;j<=m-k;j++){
      if(dp[POS(dir,now[dir],j)]){
	dp[POS(dir,next,j-k)]=1;
	dp[POS(dir,next,j+k)]=1;
      }
    }
    now[dir]=next;
  }
  printf("%s\n",dp[POS(0,now[0],x)] && dp[POS(1,now[1],y)]?"Yes":"No");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

i64 N, X, a[2020];

int main() {
    cin >> N >> X;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }

    i64 ans = 0;
    for (int j = 0; j < N; ++j) {
        ans += a[j];
    }

    for (int r = 0; r < N; ++r) {
        i64 cd = X*(r+1), al = a[N-1];
        for (int j = N-1; j > 0; --j) {
            a[j] = min(a[j], a[(j-1+N)%N]);
        }
        a[0] = min(a[0], al);

        for (int k = 0; k < N; ++k) {
            cd += a[k];
        }
        ans = min(ans, cd);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
from collections import deque

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

INF = 10 ** 5
d = [[INF for i in range(W)] for j in range(H)]
d[0][0] = 0
nexts = [(-1, 0), (1, 0), (0, -1), (0, 1)]
q = deque()
q.append((0, 0))
while len(q) > 0:
  x, y = q.popleft()
  for dx, dy in nexts:
    nx, ny = x+dx, y+dy
    if nx < 0 or nx >= W or ny < 0 or ny >= H:
      continue
    if M[ny][nx] == '#' or d[ny][nx] != INF:
      continue
    d[ny][nx] = d[y][x] + 1
    q.append((nx, ny))

if d[H-1][W-1] == INF:
  print(-1)
else:
  res = 0
  for y in range(H):
    for x in range(W):
      if M[y][x] == '.':
        res += 1
  print(res-(d[H-1][W-1]+1))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define MOD 998244353LL
/// TONI BO$$ was here
/// #MLC

using namespace std;
long long dp[301][301*301];
long long dp2[301][301*301];

int v[301];

int main()
{
    int i,j,n,s;
    long long p3,rez;
    ///freopen(".in","r",stdin);
    ///freopen(".out","w",stdout);
    scanf("%d",&n);
    s=0;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&v[i]);
        s+=v[i];
    }
    dp[0][0]=1;
    for(i=1; i<=n; i++)
        for(j=0; j<=s; j++)
            if(j>=v[i])
                dp[i][j]=(dp[i-1][j]*2+dp[i-1][j-v[i]])%MOD;
            else
                dp[i][j]=(2*dp[i-1][j])%MOD;
    p3=1;
    for(i=1; i<=n; i++)
        p3=(p3*3)%MOD;
    rez=0;
    for(i=(s+1)/2; i<=s; i++)
        rez=(rez+dp[n][i])%MOD;
    if(s%2==0)
    {
        dp2[0][0]=1;
        for(i=1; i<=n; i++)
            for(j=0; j<=300*300; j++)
                if(j>=v[i])
                    dp2[i][j]=(dp2[i-1][j]+dp2[i-1][j-v[i]])%MOD;
                else
                    dp2[i][j]=(dp2[i-1][j])%MOD;
        rez=(rez-dp2[n][s/2])%MOD;
    }
    rez=p3-rez*3;
    while(rez<0)
        rez+=MOD;
    rez%=MOD;
    printf("%lld",rez);

    return 0;
}


Measured memory_bytes: 425600
#include <stdio.h>
int main(){
	int a, b, c, i, cnt=0;
	scanf("%d %d %d", &a, &b, &c);
	for(i=a; i<=b; i++){
		if(c%i==0){
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

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

int main(){
  int N;
  int d[110];
  cin >> N;
  for (int i= 0;i< N; i++){
    cin >> d[i];
  }
  int num[110] = {0};
  for (int i= 0;i<N; i++){
    num[d[i]]++;
  }
  int res = 0;
  for (int i= 1; i<=100; i++){
    if(num[i]){
      res ++ ;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(V) V.begin,V.end
const int N = 100005;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    double ans;
    double x; string s;
    while(n--)
    {
        cin >> x >> s;
        if(s[0]=='J')
        {
            ans += x;
        }
        else
        {
            ans += (double)((x)*(380000.0));
        }
        
    }

    cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int q1_num = 0;
    int q2_num = 0;
    int q3_num = 0;
    rep(i, n) {
        int p;
        cin >> p;
        if ( p <= a ) {
            ++q1_num;
        }
        else if ( p >= a + 1 && p <= b ) {
            ++q2_num;
        }
        else if ( p >= b + 1 ) {
            ++q3_num;
        }
    }
    cout << min({q1_num, q2_num ,q3_num}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> ans(100);
    ans[0] = 2;
    ans[1] = 1;
    for(int i = 2; i < n+1; i++){
        ans[i] = ans[i-1] + ans[i-2];
    }
    cout << ans[n] << endl;
}       


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
count2 = -1
count4 = 0
for i in range(n):
    if a[i] % 4 == 2:
        count2 += 1
    if a[i] % 4 == 0:
        count4 += 1
if count2 >= 1:
    n -= count2
if count4 * 2 + 1 >= n:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 14252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll t = (a-1)/x;
    if(a==0)t = -1;
    cout<<b/x-t<<endl;
}

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

int main()
{
    
    string s;
    ll i,c,ans;
    c=0,ans=0;
    cin>>s;
    for(i=0;i<s.length();i++)
    {
    	if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')
    	{
    		c++;
    	}
    	else
    	{
    		ans=max(ans,c);
    		c=0;
    	}
    }
    ans=max(ans,c);
    cout<<ans<<endl;
      
}

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

using namespace std ;

typedef long long LL ;

int b[100];
LL A , B ;
LL res ;

inline LL calc ( LL n , int k )
{
	LL t=(1ll<<k) , tmp ;
	LL cnt=(n+1ll)/(2*t)*t;
	tmp=(n+1)%(2*t);
	if ( !tmp ) return cnt ;
	else if ( tmp>t ) cnt+=tmp-t;
	return cnt ;
}

int main ()
{
	int i , cnt=0;
	scanf("%lld%lld",&A,&B);
	for ( i=0 ; (1ll<<i)<=B ; i++ ) b[++cnt]=(calc(B,i)-calc(A-1,i))%2;
	for ( i=cnt ; i>=1 ; i-- ) res=res<<1|b[i];
	printf("%lld\n",res);
	return 0 ;
}

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

typedef long long ll;

int main () {
	ll N;
	cin >> N;
	if (N%2==1) {
		cout << 0 << endl;
		return 0;
	}

	ll cnt = 0;
	for (ll f=5, fdx=1; f<=1000000000000000000; f*=5) {
		cnt += (N/f)/2;
	}

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);

		boolean[][] conds = new boolean[M][N];
		for (int i = 0; i < M; ++i) {
			Arrays.fill(conds[i], false);
		}
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			int k = Integer.parseInt(tokens[0]);
			for (int j = 0; j < k; ++j) {
				int index = Integer.parseInt(tokens[j + 1]);
				conds[i][index - 1] = true;
			}
		}
		int[] nums = new int[M];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < M; ++i) {
			nums[i] = Integer.parseInt(tokens[i]);
		}
		int count = 0;
		for (int v = 0; v < Math.pow(2.0, N); ++v) {
			boolean[] pattern = genSwitchPattern(v, N);
			if (check(conds, pattern, nums)) {
				++count;
			}
		}
		System.out.println(count);
		in.close();
	}

	static boolean check(boolean[][] conds, boolean[] pattern, int[] nums) {
		for (int i = 0; i < conds.length; ++i) {
			boolean checkResult = check(conds[i], pattern, nums[i]);
			if (!checkResult) {
				return false;
			}
		}
		return true;
	}

	static boolean check(boolean[] cond, boolean[] pattern, int num) {
		int count = 0;
		for (int i = 0; i < cond.length; ++i) {
			if (cond[i] && pattern[i]) {
				++count;
			}
		}
		if (count % 2 == num) {
			return true;
		} else {
			return false;
		}

	}

	static boolean[] genSwitchPattern(int v, int len) {
		boolean[] result = new boolean[len];
		Arrays.fill(result, false);
		for (int i = 0; i < len; ++i) {
			if (v % 2 != 0) {
				result[i] = true;
			}
			v /= 2;
		}
		return result;
	}

}

Measured memory_bytes: 23764
#include <stdio.h>

int main(){
	int a, b, c1, c2;
  	
  	scanf("%d %d %d", &a, &b, &c2);
  
  	c1 = b/a;
  
  	if(c1 >= c2 ){
  		printf("%d", c2);
    }else{
    	printf("%d", c1);
    }
  
  	return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int check = 0;
    if(s.at(0) != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    if(s.at(1) >= 'A' && s.at(1) <= 'Z'){
        cout << "WA" << endl;
        return 0;
    }
    if(s.at(s.size()-1) >= 'A' && s.at(s.size()-1) <= 'Z'){
        cout << "WA" << endl;
        return 0;
    }
    for(int i = 2; i < s.size() - 1; i++ ){
        if(s.at(i) == 'C'){
            if(check == 1){
                cout << "WA" << endl;
                return 0;
            }else{
                check = 1;
            }
        }else if(s.at(i) >= 'A' && s.at(i) <= 'Z'){
        cout << "WA" << endl;
        return 0;
        }
    }
    if(check == 1){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
H, W = map(int, input().split())


frame = [['#' for _ in range(W+2)] for _ in range(H+2)]

mat = [['#' for _ in range(W)] for _ in range(H)]
for i in range(H):
    line = input()
    for j in range(W):
        mat[i][j] = line[j]

for i, row in enumerate(mat):
    for j, char in enumerate(row):
        frame[i+1][j+1] = char

for i in frame:
    for j in i:
        print(j, end="")
    print()


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

int main() {
  int N, K, Q;// N人、Kポイント、Q回の正解
  cin >> N >> K >> Q;
  vector<int> result(N, 0);
  for (int i = 0; i < Q; i++) {
  	int answerer;
    cin >> answerer;
    result[answerer - 1] ++;
  }
  for (int i = 0; i < N; i++) {
  	if (Q - result[i] >= K) {
    	cout << "No" << endl;
    } else {
    	cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int c = saori.saori_hayami();
		int d = saori.saori_hayami();
		boolean flg = true;
		if(Math.abs(a-b) > d || Math.abs(b-c) > d){
			flg = false;
			if(Math.abs(a-c) <= d){
				flg = true;
			}
		}
		if(flg){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define pb push_back
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(type,arr,n)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//=======================
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
//=======================
const int MOD = 1000000007;
const int N = 300005, M = N;
//=======================
vi g[N],adj[N];
int n, m, s, w, W, S, k, i, l, j, p, q, pr, fi, md;


void abhinay()
{
   
    #ifndef ONLINE_JUDGE   
        freopen("input.txt", "r", stdin);   
        freopen("output.txt", "w", stdout);   
    #endif   
    
}

int main(){
    abhinay();
    cin>>n;
    vi dp(n+1,MOD),v(n+1); 
    dp[0]=0;
    fo(i,n) cin>>v[i];
    dp[1] = abs(v[1] - v[0]); 
    for (int i = 2; i < n; i++)
        dp[i] = min(abs(v[i] - v[i - 1]) + dp[i - 1], abs(v[i] - v[i - 2]) + dp[i - 2]);
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 18048
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
diff=[0]*(m-1)
for i in range(m-1):
  diff[i]=x[i+1]-x[i]
diff=sorted(diff)[::-1]
print((x[-1]-x[0])-sum(diff[:n-1]))

Measured memory_bytes: 13968
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  b-=a;
  b=abs(b);
  for(ll i=0;i<=n;i++){
    ll j=n-1-i;
    if(min(i*c-j*d,i*d-j*c)<=b && b<=max(i*c-j*d,i*d-j*c)){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;

int n, l, t;
int pos[MaxN];

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

	int s = 0;
	for (int i = 0; i < n; ++i)
	{
		pos[i] = getint();

		if (getint() == 1)
		{
			int k = (pos[i] + t) / l;
			s = (s + k) % n;
			pos[i] = (pos[i] + t) % l;
		}
		else
		{
			int k = (t + l - pos[i] - 1) / l;
			s = ((s - k) % n + n) % n;
			pos[i] = ((pos[i] - t) % l + l) % l;
		}
	}

	sort(pos, pos + n);

	for (int i = s; i < n; ++i)
		cout << pos[i] << endl;
	for (int i = 0; i < s; ++i)
		cout << pos[i] << endl;

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int num,ans,i,d,x,n;
string s;
int main() {
   cin>>n>>s;
    for(int i=0;i<s.size();i++)
      {
	  if(s[i]=='I')x++;
      else
         x--;
         ans=max(ans,x);
	  }
     cout<<ans;
      
  }

  


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


int main(){
  int N, X, T;
  cin >> N >> X >> T;

  //たこやきを焼く回数を求める
  int times = (N + X -1) / X;

  //答えを求める。
  int ans = times * T;

  cout << ans << endl;

}

Measured memory_bytes: 3684
/*input
10 8
##...#.#
##...#.#
..###.#.
#.##.#.#
.#..#.#.
..##.#.#
##.#.#..
...#.#..
###.#.##
###..###
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 2020
#define INF 0x3f3f3f3f

int F(int a , int b){ return a != b; }
int n , m , v[MAX][MAX] , x[MAX] , l[MAX] , r[MAX];
int L(int id , int val){ return x[id] < val ? id : L(l[id] , val); }
int R(int id , int val){ return x[id] < val ? id : R(r[id] , val); }
string s[MAX];
int32_t main(){
    IOS;
    cin >> n >> m;

    int ans = max(n , m);
    REP(i , 1 , n + 1) cin >> s[i] , s[i] = " " + s[i];
    REP(i , 1 , n + 0){
        int pos = 1;
        REP(j , 1 , m + 1){
            while(pos <= m && F(s[i + 0][j] , s[i + 1][j]) == F(s[i + 0][pos] , s[i + 1][pos]))
                pos ++;
            v[i][j] = pos;
        }
    }
    // REP(i , 1 , n + 0) {REP(j , 1 , m + 1) cout << v[i][j] << " " ; cout << endl;}
    REP(j , 1 , m + 1){
        REP(i , 1 , n + 0) x[i] = v[i][j] - j;
        REP(i , 1 , n + 0)  l[i] = L(i - 1 , x[i]);
        RREP(i , n - 1 , 1) r[i] = R(i + 1 , x[i]); 
        REP(i , 1 , n + 0){
            ans = max(ans , (r[i] - l[i]) * x[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36096
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a, b, c = sorted(a), sorted(b), sorted(c)

ans = 0
for i in b:
    up_index = bisect.bisect_left(a,i)
    down_index = bisect.bisect_right(c,i)
    ans += up_index * (n-down_index)

print(ans)


Measured memory_bytes: 23232
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, N);

	int ret = 0;
	rep(i, N) {
		while (a[i] % 2 == 0) {
			ret++;
			a[i] /= 2;
		}
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while(sc.hasNext()) {
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			int c3 = sc.nextInt();

			int sum = c1 + c2; //????????????????????¨??????????????????????¶????
			int count  = 0;
			for(int $ = 1; $ < 11; $++) {
				if($ == c3) {
					continue;
				}
				if((sum + $) > 20) {
					break;
				}
				count++;
			}
			if(count >=  4) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

	}

}

Measured memory_bytes: 25812
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
int A,B;
string S,T;
//=============================
void input()
{
    cin>>A>>B;
    cin>>S;
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    bool ans = true;

    if (S.size() != A+B+1) {
        ans = false;
    } else if (S[A] != '-') {
        ans = false;
    } else {
        rep(i,0,A+B){
            if (i==A)continue;

            if (S[i] < '0' || S[i] > '9') ans=false;
        }
    }
    cout<<(ans ? "Yes" : "No")<<endl;



}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
s=gets.chomp.split("").map &:to_i
sum1=0
sum2=0
for i in 0...s.size
  a=i%2
  sum1+=1 if s[i]!=a
end
ans=sum1
for i in 0...s.size
  a=(i+1)%2
  sum2+=1 if s[i]!=a
end
puts [ans,sum2].min


Measured memory_bytes: 20000
#include <stdio.h>
#include <string.h>
 
#define MAX 1000
#define max(a,b) (a < b ? b : a)
 
int main(){
  int Q,i,j,l1,l2,dp[MAX+1][MAX+1];
  char X[MAX+1],Y[MAX+1];
  scanf("%d",&Q);
  while(Q--){
    scanf("%s %s",X,Y);
    l1 = strlen(X);
    l2 = strlen(Y);
    memset(dp,0,sizeof(dp));
    for(i = 0 ; i < l1 ; i++){
      for(j = 0 ; j < l2 ; j++){
        if(X[i] == Y[j]){
          dp[i+1][j+1] = dp[i][j] + 1;
        }else{
          dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
      }
    }
    printf("%d\n",dp[l1][l2]);
  }
  return 0;
}


Measured memory_bytes: 5780
a = gets.chomp.split(" ").map(&:to_i)
a.sort!

if ((a[2] - a[1]) + (a[2] -a[0])) % 2 == 0 then
    puts ((a[2] - a[1]) + (a[2] -a[0])) /2
else
    puts ((a[2] - a[1]) + (a[2] -a[0])) /2 + 2
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
// r -> l or l -> r
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1e9;
    rep(i,n) {
        int l = i;
        int r = i+k-1;
        if(r >= n) break;
        int a = abs(x[l]) + abs(x[l]-x[r]);
        int b = abs(x[r]) + abs(x[r]-x[l]);
        int res = min(a, b);
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
import sys
from itertools import accumulate

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, K = lr()
S = [list(map(int, sr())) for _ in range(H)]
Scum = [list(accumulate(x)) for x in S]
answer = 10000
for bit in range(1<<(H-1)):
    count = 0
    for i in range(H-1):
        if bit >> i & 1:
            count += 1
    bit += 1 << H-1 # 最後の切れ目
    # 縦のラインは貪欲法
    prev = -1
    w = 0
    while w < W:
        white = 0
        cut = False
        for i in range(H):
            white += Scum[i][w] - (Scum[i][prev] if prev >= 0 else 0)
            if (bit >> i) & 1: # 切れ目が来た
                if white > K:
                    cut = True
                white = 0
        if cut:
            if prev == w-1: # 一列でKをオーバー
                break
            count += 1
            prev = w-1
        else:
            w += 1
    else:
        answer = min(answer, count)

print(answer)


Measured memory_bytes: 45404
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
string s;
int main()
{
	std::ios::sync_with_stdio(false);
	int now = 0;
	long long ans = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i ++)
		if(s[i] == 'W')
		{
			ans += i - now;
			now ++;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll INF = 1001001001001001001;
signed main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> b=a;
    sort(ALL(a));
    sort(ALL(b),greater<ll>());
    ll l=-INF; ll r=INF;
    while(r-l>1){
        ll res=0;
        ll mid=(l+r)/2;
        //mid miman
        for(ll i=0;i<n;i++){
            if(a[i]==0){
                if(0<mid){
                    res+=n-1;
                }
                continue;
            }
            if(a[i]>0){
                if(a[i]*a[0]>=mid) continue;
                int li=0,ri=n;
                while(ri-li>1){
                    int midi=(li+ri)/2;
                    if(a[i]*a[midi]<mid) li=midi;
                    else ri=midi;
                }
                res+=li+1;
            }else{
                if(a[i]*b[0]>=mid) continue;
                int li=0,ri=n;
                while(ri-li>1){
                    int midi=(li+ri)/2;
                    if(a[i]*b[midi]<mid) li=midi;
                    else ri=midi;
                }
                res+=li+1;
            }
            if(a[i]*a[i]<mid) res--;
        }
        //if(res%2==1) cout << "NO"<<res<<mid;
        res/=2;
        if(res<=k-1) l=mid;
        else r=mid;
        //cout << l << " "<< r << endl;
    }
    cout << l << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int i;
    int num[10];
    char n[10];
    gets(n);
    for(i=0;i<4;i++)
    {
        num[i]=n[i]-48;
    }
    if(num[0]+num[1]+num[2]+num[3]==7)
        printf("%d+%d+%d+%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]+num[1]+num[2]-num[3]==7)
        printf("%d+%d+%d-%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]+num[1]-num[2]+num[3]==7)
        printf("%d+%d-%d+%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]+num[1]-num[2]-num[3]==7)
        printf("%d+%d-%d-%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]-num[1]+num[2]+num[3]==7)
        printf("%d-%d+%d+%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]-num[1]+num[2]-num[3]==7)
        printf("%d-%d+%d-%d=7", num[0], num[1], num[2], num[3]);
    else if(num[0]-num[1]-num[2]+num[3]==7)
        printf("%d-%d-%d+%d=7", num[0], num[1], num[2], num[3]);
    else
        printf("%d-%d-%d-%d=7", num[0], num[1], num[2], num[3]);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	string s;
	cin>>s;
	
	string ans="";
	
	for(auto &elm:s){
		if(elm=='0')ans+='0';
		if(elm=='1')ans+='1';
		if(elm=='B')ans = ans.substr(0,ans.size()-1);
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  string S;
  cin >> S;

  vl west(N, 0), east(N, 0);

  rep2(i, 1, N) west[i] = west[i - 1] + (S[i - 1] == 'W' ? 1 : 0);
  rep_inv(i, N - 2, -1) east[i] = east[i + 1] + (S[i + 1] == 'E' ? 1 : 0);

  ll ans = N + 1;

  rep(i, N) ans = min(ans, west[i] + east[i]);

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


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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back


int main(void){
  ll n, m, k;
  bool ok = false;
  cin >> n >> m >> k;
  reps(i,0,n)reps(j,0,m){
    if(i * m + j * n - i * j * 2 == k){
      ok = true;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
(defun solve (n a &optional (ans 0))
  (dotimes (i n ans)
    (when (and
            (oddp (1+ i))
            (oddp (elt a i)))
      (incf ans))))

(defun main ()
  (let* ((n (read))
         (a (read-from-string (concatenate 'string "(" (read-line) ")"))))
    (princ (solve n a))
    (fresh-line)))

(main)


Measured memory_bytes: 24556
import java.util.*;


public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int[] a=new int[n];
		
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		
		long ans=0;
		for(int i=1;i<n;i++) {
			if(a[i-1]>a[i]) {
				ans+=(a[i-1]-a[i]);
				a[i]=a[i-1];
			}
		}
		System.out.println(ans);

	

	
	}
}


Measured memory_bytes: 59816
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def getPrice(total:Int,a:Int,b:Int,c:Int,d:Array[Array[Array[Int]]]):Int = {
    if(total==0) {
      d(a)(b)(c)=((a/5)*5*380*0.8+((a%5)*380)*1.0+(b/4)*4*550*0.85+(b%4)*550*1.0+(c/3)*3*850*0.88+(c%3)*850).toInt
      d(a)(b)(c)
    } else if(d(a)(b)(c)>0) d(a)(b)(c)
    else {
      var min = Int.MaxValue
      if(total==200 || total>=400) {
        val p = getPrice(total-200,a+1,b,c,d)
        if(p<min) min = p
      }
      if(total==300 || total>=500) {
        val q = getPrice(total-300,a,b+1,c,d)
        if(q<min) min = q
      }
      if(total==500 || total>=700) {
        val r = getPrice(total-500,a,b,c+1,d)
        if(r<min) min = r
      }
      min
    }
  }

  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]
    var n = 0
    while({n=readInt;n}!=0) {
      val d = Array.ofDim[Int](n/200+1,n/300+1,n/500+1)
      b+=getPrice(n,0,0,0,d)
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 44484
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, T;
	static HashSet<String> keySet = new HashSet<String>();
	static String[] event;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		N = sc.nextInt();
		for(int i = 0; i < N; i++){
			keySet.add(sc.next());
		}
		T = sc.nextInt();
		event = new String[T];
		for(int i = 0; i < event.length; i++){
			event[i] = sc.next();
		}
		return true;
	}
	
	static void solve(){
		boolean isLocked = true;
		for(int i = 0; i < event.length; i++){
			if(keySet.contains(event[i])){
				if(isLocked){
					System.out.println("Opened by " + event[i]);
					isLocked = false;
				}else{
					System.out.println("Closed by " + event[i]);
					isLocked = true;
				}
			}else{
				System.out.println("Unknown " + event[i]);
			}
		}
		keySet.remove(keySet);
	}
}

Measured memory_bytes: 20556
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

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

using namespace std;


int inputValue() {
  int a;
  cin >> a;
  return a;
};
void inputVector(vector<int>* v) {
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  int a;
  while (cin >> a) {
    if (a == -1)break;
    v->push_back(a);
  }
};

void inputVector(vector<int> * p, int a) {
  rep(i, a) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}

void inputVector2(vector<vector<int>>& v, int r, int c) {
  int temp;
  for (size_t i = 0; i < r; i++)
  {
    for (size_t j = 0; j < c; j++)
    {
      scanf("%d", &temp);
      v[i][j] = temp;
    }
  }
}
void inputVector3(vector<int>* v0, vector<int>* v1) {
  int a;
  unsigned short count = 0b0;
  while (cin >> a) {
    if (a == -1)break;
    if (count)v0->push_back(a); else v1->push_back(a);
    count = count ^ 1;
  }
};

template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  }
  else {
    cout << a << "\n";
  }
}

int main(int argc, const char * argv[]) {
  int a, b;
  string s;
  scanf("%d", &a);
  scanf("%d", &b);
  if ((a*b) % 2 == 1) {
    s = "Yes";
  }
  else {
    s = "No";
  }
  cout << s << endl;
}

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

int n;
int t[102][102];
int sum[102][102];

int main(){
  while(cin >> n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> t[i][j];

        sum[i][j] = t[i][j]
          + (0 <= i - 1 ? sum[i - 1][j] : 0)
          + (0 <= j - 1 ? sum[i][j - 1] : 0)
          - (0 <= i - 1 && 0 <= j - 1 ? sum[i - 1][j - 1] : 0);
      }
    }

    int ans = INT_MIN;

    for(int si = 0; si < n; si++){
      for(int sj = 0; sj < n; sj++){
        for(int gi = si; gi < n; gi++){
          for(int gj = sj; gj < n; gj++){
            int calc = sum[gi][gj]
              - (0 <= si - 1 ? sum[si - 1][gj] : 0)
              - (0 <= sj - 1 ? sum[gi][sj - 1] : 0)
              + (0 <= si - 1 && 0 <= sj - 1 ? sum[si - 1][sj - 1] : 0);

            ans = max(ans, calc);
          }
        }
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

bool dp[2][16161];
string s; 

bool solve(int g, int mod, vector<int> a) {
	
	rep(i,2) rep(j,16161) dp[i][j]=false;

	dp[0][8000]=true;
	
	int i=0;
	if (!mod) {
		rep(j,16161) {
			if (!dp[0][j]) continue;
			dp[i][j]=false;
			dp[i+1][j+a[i]]=true;
			// cout << "i = "<<i<<", j+a[i] = "<<j+a[0] << endl;
		}
	}

	for (; i < a.size(); ++i) {
		rep(j,16161) {
			if (!dp[i%2][j]) continue;
			dp[i%2][j]=false;
			dp[(i+1)%2][j+a[i]]=true;
			dp[(i+1)%2][j-a[i]]=true;
			// cout<< "i = "<<i%2<<", j+a[i] = "<<j+a[i]<<", j-a[i] = "<<j-a[i]<< endl;
		}
	}

	if (dp[a.size()%2][g+8000]) return true;
	else return false;
}

int main(int argc, char const *argv[]) {
	int x,y;
	cin>>s>>x>>y;
	int n = s.length();
	vector<int> a;
	vector<int> X,Y;

	// ランレングス変換をします
	int cnt=0;
	rep(i,n) {
		if (s[i]=='F') cnt++;
		else {
			a.push_back(cnt);
			cnt=0;
		}
	}
	if (cnt) a.push_back(cnt);

	rep(i,a.size()) {
		if (i%2==0) X.push_back(a[i]);
		else Y.push_back(a[i]);
	}

	if (solve(x,0,X)&&solve(y,1,Y)) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main()
{
	int sum;
	char str[1100];
	int i;
	for(i=0;i<1100;i++){
		str[i]=0;
	}
	
	while(1){
		scanf("%s",str);
		if(strcmp(str,"0")==0){
			break;
			
		}
		
		sum=0;
		for(i=0;str[i]!='\0';i++){
			sum+=str[i]-'0';
		}
		
		printf("%d\n",sum);
		
	}
	
  return 0;
}

Measured memory_bytes: 536
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
const int mod = 1e9+7;

int h , w;
int x , y;


int main(){
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(10) << (1.000 * w * h) / 2 << " ";
    if(w % 2 == 0 && h % 2 == 0 && x == w/2 && y == h/2){
        cout << 1;
    } else {
        cout << 0;
    }

}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int main(){
	int a1=read(),b1=read(),a2=read(),b2=read();
	if(a1==a2)puts("0");
	else puts("1");
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;
        
//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




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

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ull modpow(ull a, ull b) {
	ll retval = 0;

	if (b == 0) { return 1; }

	else if (b % 2 == 0) {
		retval = modpow(a, b / 2) % mod;
		return (retval * retval) % mod;
	}

	else {
		
		return ((a % mod) * modpow(a, b - 1)) % mod;
	}
}

ull modkaijou(ull a) {

	if (a == 1 || a == 0) { return 1; }

	ll retval = 1;

	for (ull i = a; i >= 1; i--) {
		retval = (retval * (i % mod)) % mod;
	}

	return retval % mod;
}

ull modcomb(ull a, ull b) {

	if (a == 0 || b == 0) return 1;

	return (((modkaijou(a) * modpow(modkaijou(a-b), mod - 2)) % mod) * modpow(modkaijou(b), mod - 2)) % mod;
}



stack<int> to_1;


class DisjointSet {
public:
	vector<int> p, rank, num;


	DisjointSet() {}

	DisjointSet(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		num.resize(size, 0);
		rep(i, size) { p[i] = i; rank[i] = 0; num[i] = 1; }
	}

	bool same(int x, int y) {

		return findSet(x) == findSet(y);

	}

	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x, int y) {
		if (rank[x] > rank[y]) {

			p[y] = x;
			num[x] += num[y];

		}

		else {
			p[x] = y;
			num[y] += num[x];
			if (rank[x] == rank[y]) {

				rank[y]++;
			}

		}


	}


	ll NumberOfElements(int x) {

		return num[findSet(x)];

	}


	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
			num[x] = 1;
		}

		return p[x];
	}



};




bool compare_b(pint a, pint b) {
	if (a.first < b.first) {
		return true;
	}
	else if (a.first == b.first) {
		return a.second < b.second;
	}

	else {
		return false;
	}

}

int ketasuu(int a) {

	int ret = 1;
	int val = a;
	while (val / 10 != 0) {

		ret += 1;
		val /= 10;
	}
	return ret;
}




string S;

ll N, Q;
ll Sum[100005];
vector<pint> query;
int main() {
	int l, r;
	cin >> N >> Q;

	cin >> S;

	rep(i, Q) {
		cin >> l >> r;
		query.push_back({ l, r });
	}


	ll ans = 0;
	ll val = 0;

	ll index = 0;
	rep(i, S.size()-1) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			Sum[i + 1] = Sum[i] + 1;
		}

		else {
			Sum[i + 1] = Sum[i];
		}

	}




	rep(i, Q) {
		
		cout << Sum[query[i].second - 1] - Sum[query[i].first - 1] << endl;
	}


	
	return 0;
}

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

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

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

int main() {
  long long a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}
  

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

using namespace std;

int main()
{    
    // 記述はないがmは高々5万
    string s;
    cin >> s;
    string ans = "ARC";
    if(s == "ARC"){
        ans = "ABC";
    }

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

Measured memory_bytes: 3632
n = int (input())
runrun = [i+1 for i in range(9)]
count = 9
if n < 10:
    print(runrun[n-1])
    exit(0)


def calc_next_runrun(runrun, count):
    new_runrun=[]
    for run in runrun:
        hitoketa = run % 10
        if hitoketa == 0:
            new_runrun.append(run*10 + 0)
            new_runrun.append(run*10 + 1)
        elif hitoketa == 9:
            new_runrun.append(run*10 + 8)
            new_runrun.append(run*10 + 9)
        else:
            new_runrun.append(run*10 + hitoketa -1)
            new_runrun.append(run*10 + hitoketa )
            new_runrun.append(run*10 + hitoketa +1)
    new_count = len(new_runrun)
    if new_count + count >= n:
        print(new_runrun[n-count-1])
    else:
        calc_next_runrun(new_runrun, new_count+count)

calc_next_runrun(runrun, count)

Measured memory_bytes: 11736
#include <stdio.h>

int main(void) {
	int N, D, X;
	int A[100];
	int count = 0;
	scanf("%d%d%d", &N, &D, &X);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	for (int i = 0; i < N; i++) {

		for (int j = 0; j < D; j++) {
			if (D>= j * A[i] + 1) {

				count++;

			}
		}
	}



	printf("%d\n", count + X);



	return 0;

}

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

int main() {
	int n;
	while(cin >> n && n){
		int W, H, maze[110][110] = {0}, sum[110][110] = {0}, S, T, x, y, ans = 0;
		cin >> W >> H;
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &x, &y);
			x--; y--;
			maze[y][x] = 1;
		}
		cin >> S >> T;
		for(int i = 1; i <= H; ++i){
			for(int j = 1; j <= W; ++j){
				sum[i][j] = maze[i - 1][j - 1] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
			}
		}
		for(int i = 0; i + T <= H; ++i){
			for(int j = 0; j + S <= W; ++j){
				ans = max(ans, sum[i + T][j + S] - sum[i][j + S] - sum[i + T][j] + sum[i][j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1344