akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int cnt,n;
    int i;
    string s;
    cin>>s;
    n=s.size();
    cnt=0;
   // cout<<n/2<<endl;
    for(i=0;i<n/2;i++){
     //   cout<<s[i]<<" "<<s[n-i-1]<<endl;
        if(s[i]!=s[n-i-1])    cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        this.BlockLength = int.Parse(Reader.ReadLine());
        this.Map[0] = Reader.ReadLine().ToArray();
        this.Map[1] = Reader.ReadLine().ToArray();
        long ans = 1;
        int idx = 0;
        bool prevTate = true;
        while(idx<BlockLength) {
            if(Map[0][idx]==Map[1][idx]) {
                if(idx==0) {
                    ans = 3;
                } else if(prevTate) {
                    ans = ans * 2;
                }
                prevTate = true;
                idx++;
            } else {
                if(idx == 0) {
                    ans = 6;
                } else if(!prevTate) {
                    ans = ans * 3;
                } else {
                    ans = ans * 2;
                }
                prevTate = false;
                idx += 2;
            }

            ans = ans % Mod;
        }
        Console.WriteLine(ans%Mod);
    }

    private int BlockLength = 0;

    private long Mod = 1000000000 + 7;


    private Dictionary<char, int[]> MapDic = new Dictionary<char, int[]>();

    private char[][] Map = new char[2][];

    private Dictionary<string, long> dic = new Dictionary<string, long>();

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13400
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from fractions import*;a,b,c=map(int,input().split());print('YNEOS'[c%gcd(a,b)>0::2])\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 5904
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N = 5000000;
char      buf[N];
inline int readInt(int &p){
  /*
  int ret = 0;
  char c;
  while((c=getchar()) && isdigit(c)){
    ret = ret * 10 + (c-'0');
  }
  return ret;
  */
  int ret = 0;
  while(p < N && !(isdigit(buf[p])))p++;
  for(;p < N && isdigit(buf[p]) && buf[p] != '\0';p++){
    ret = ret * 10 + (buf[p]-'0');
  }
  return ret;
}

void outint(int a){
  if (a == 0)return;
  outint(a/10);
  putchar('0' + a%10);
}

inline void write(int &p,char *buf,int ans){
  if (ans == 0)return;
  write(p,buf,ans/10);
  buf[p++] = '0'+ans%10;
}

main(){
  int n,s;
  int p = 0;
  int inp=0;
  //read(buf,100000,stdin);
  read(0,(void*)buf,N);
  //cout << buf << endl;
  //return 0;
  while(true){
    n = readInt(inp);
    if (n==0)break;
    s = readInt(inp);
    int r[101]={0};
    int sum[101];
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt(inp);r[tmp]++;
    }
    sum[0] = 0;
    for(int i=1;i<101;i++){
      sum[i] = sum[i-1] + r[i];
    }
    int ans = 0;
    for(int i=1;i != 101;i++){
      if (r[i] && i+i > s)ans += r[i]*(r[i]-1)/2;
      for(int j=i+1;j<101;j++){
	//if (i+j>s)ans += r[i]*r[j];
	if (i+j > s){
	  ans += r[i] * (sum[100] - sum[j-1]);
	  break;
	}
      }
    }
    //printf("%d\n",ans);
    if (ans == 0){
      buf[p++] = '0';
    }else     write(p,buf,ans);
    buf[p++] = '\n';
  }
  buf[p-1] = '\0';
  puts(buf);
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long Maxn=200000+20,inf=0x3f3f3f3f;
long long n,m,k,ans;
long long a[Maxn],b[Maxn];
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read(),m=read(),k=read();
	for(long long i=1;i<=n;++i)
	a[i]=read()+a[i-1];
	for(long long i=1;i<=m;++i)
	b[i]=read()+b[i-1];
	for(long long i=0;i<=n;++i)
	{
		if(a[i]>k)break;
		long long l=0,r=m;
		while(l<r)
		{
			long long mid=(l+r)>>1;
			++mid;
			if(b[mid]<=k-a[i])l=mid;
			else r=mid-1;
		}
		ans=max(ans,i+l);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6816
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n;
    vector<LL> dp;
    Problem(LL n):n(n),dp(n+1,-1){};
    /*LL calc(int x){
        DBG(x)
        if(x<0)return 1;
        if(dp[x]>=0)return dp[x];
        LL ret=((n-1)*(n-1)+calc(x-1))%MOD;
        for(int i=2; i<=n; ++i){
            ret=(ret+calc(x-i-1))%MOD;
        }
        DBG(x,ret)
        return dp[x]=ret;
    }*/
    void solve(){
        dp[0]=1;
        dp[1]=n;
        LL cnt=n-1;
        LL sum=0;
        for(int i=2; i<=n; ++i){
            dp[i]=((n-1)*(n-1)+dp[i-1]+cnt+sum)%MOD;
            sum=(sum+dp[i-2])%MOD;
            --cnt;
        }
        cout << dp[n] <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 8064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 15 08:50:44 2020

@author: naoki
"""
from collections import deque

N = int(input())
uvws = [list(map(int, input().split())) for _ in range(N-1)]

routes = [[] for _ in range(N)]
for uvw in uvws:
    u = uvw[0]-1
    v = uvw[1]-1
    w = uvw[2]
    
    routes[u].append([v,w])
    routes[v].append([u,w])
    
    
colors = [-1 for _ in range(N)]
todo = deque()
todo.append(0)
colors[0] = 0


while len(todo)>0:
    checking = todo.pop()
    for route in routes[checking]:
        destination = route[0]
        weight = route[1]
        
        if colors[destination] == -1:
            if weight%2 == 0:
                colors[destination] = colors[checking]
            else:
                colors[destination] = 1 - colors[checking]
            todo.append(destination)

for i in range(N):
    print(colors[i])

Measured memory_bytes: 123588
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;
const long long mod = 917120411LL;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int sieve[1000010];
void make_sieve()
{
    for (int i = 0; i < 1000010; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 0; i * i < 1000010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; j * i < 1000010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
}

ll GCD(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
ll pow_mod(ll x, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res = res * x;
        }
        x = x * x;
        n >>= 1;
    }
    return res;
}

int p[200010];
int a[20010] = {0};
int b[20010] = {0};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;

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

    for (int i = 0; i < N; ++i)
    {
        a[i] = 1 + i * 30000;
        b[N - i - 1] = 1 + i * 30000;
    }

    for (int i = 0; i < N; ++i)
    {
        a[p[i]] += i;
    }

    for (int i = 0; i < N; ++i)
    {
        if (i)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
    for (int i = 0; i < N; ++i)
    {
        if (i)
            cout << " ";
        cout << b[i];
    }
    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main(void) {
  int paper = 0;
  int n;
  scanf("%d", &n);
  if(n % 2 == 0) {
    paper = n / 2;
  } else {
    paper = n / 2 + n % 2;
  }
  printf("%d", paper);
  return 0;
}


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

int main()
{
    int a[5];
    int k;
    for(int i = 0; i < 5; i++)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    for(int i = 4; i >= 0; i--)
    {
        for(int j = i-1; j >= 0; j--)
        {
            if(a[i] - a[j] > k)
            {
                printf(":(");
                return 0;
            }
        }
    }
    printf("Yay!");
    return 0;
}


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

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

int main()
{
    int K;
    cin >> K;
    long long res = 0;
    for (int a = 1; a <= K; a++)
    {
        for (int b = 1; b <= K; b++)
        {
            for (int c = 1; c <= K; c++)
            {
                res += GCD(GCD(a, b), c);
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int N = min(B, D) - max(A, C);
  if(N < 0) {
    N = 0;
  }
  cout << N << endl;
}


Measured memory_bytes: 3564
# print('input >>')
As = []
As += list(map(int,(input().split())))
As += list(map(int,(input().split())))
As += list(map(int,(input().split())))
N = int(input())
bingo = [0] * 9
for b in range(N):
    b = int(input())
    if b in As:
        bingo[As.index(b)] = 1    

# print('-----output-----')
if bingo[0]*bingo[1]*bingo[2] == 1 or bingo[3]*bingo[4]*bingo[5] == 1 or bingo[6]*bingo[7]*bingo[8] == 1 or bingo[0]*bingo[3]*bingo[6] == 1 or bingo[1]*bingo[4]*bingo[7] == 1 or bingo[2]*bingo[5]*bingo[8] == 1 or bingo[0]*bingo[4]*bingo[8] == 1 or bingo[2]*bingo[4]*bingo[6] == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,m;
map<ll,ll> a;

int main(){
	cin>>n>>m;
	ll t=0;
	a[0]++;
	for(int i=0;i<n;i++){
		ll A;
		cin>>A;
		(t+=A)%=m;
		a[t]++;
	}
	ll res=0;
	for(auto i=a.begin();i!=a.end();i++){
		ll x=i->second;
		res+=x*(x-1)/2;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}

int n;
vector<ll> t;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    t.resize(n);
    rep(i, 0, n) cin >> t[i];
    ll ans = t[0];
    rep(i, 1, n) {
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int arr[100000];
int main(){
  int N,Q,A,B,C;
  long long int S = 0;
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> A;
    arr[A-1]++;
    S += (long long int)A;
  }
  cin >> Q;
  for(int i = 0;i < Q;i++){
    cin >> B >> C;
    S += (long long int)(arr[B-1]*(C-B));
    arr[C-1] += arr[B-1];
    arr[B-1]=0;
    cout << S << endl;
  }
  return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  ll ans = 0;
  REP(i, N) {
    int l, r;
    cin >> l >> r;
    ans += (r - l + 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[201],b[201];
ll n,w;
ll dp[201][200001];
ll rec(ll idx, ll weight)
{
	if(weight>w)return -1e9;
	if(weight==w)return 0;
	if(idx==n)return 0;
	if(dp[idx][weight]!=-1)return dp[idx][weight];
	ll op1=rec(idx+1,weight+a[idx])+b[idx];
	ll op2=rec(idx+1,weight);
	return dp[idx][weight]=max(op1,op2);
	
}

int main()
{
	cin>>n>>w;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<rec(0,0);
	
}

Measured memory_bytes: 317636
package main
import "fmt"
func main() {
  var h,w,m int
  var s string
  fmt.Scan(&h,&w)
  m = 0
  for i:=0;i<h;i++ {
    fmt.Scan(&s)
    for j:=0;j<w;j++ {
      if s[j:j+1] == "#" { m++ }
    }
  }
  if m == h+w-1 {
    fmt.Println("Possible")
  } else {
    fmt.Println("Impossible")
  }
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>

using namespace std;
const int Max_L(50);
typedef long long int LL;

int L, len, D[Max_L], N[Max_L], X[Max_L];
char input[Max_L];
LL Ans;

int work(int p, int x)
{
	int Ret(0);
	for (int c = (p == len - 1 ? 1 : 0);c <= 9;++c)
		if (0 <= c - x && c - x <= 9)
			++Ret;
	return Ret;
}

bool check()
{
	for (int i = len - 1, j;i >= 0;--i)
	{
		X[j = i] = N[i];
		while (X[j] < 0)
		{
			if (j == len - 1)
				return false;
			X[j] += 10, --X[++j];
		}
	}
	for (int i = 0;i <= len - 1;++i)
		if (X[i] != D[i])
			return false;
	return true;
}

void dfs(int p, int a, int b, int v, LL Ret = 1LL)
{
	if (!Ret)
		return;
	if (a <= b)
	{
		if (a == b)
			Ret *= work(a, 0);
		if (check())
			Ans += Ret;
		return;
	}
	int x = (D[p] + v) % 10;
	if (x == 0)
		if (D[p] + v == 0)
			N[p] = 0, N[len - 1 - p] = 0, dfs(p + 1, a - 1, b + 1, 0, Ret * work(a, 0));
		else
			N[p] = 0, N[len - 1 - p] = 0, dfs(p + 1, a - 1, b + 1, 1, Ret * work(a, 0));
	else
	{
		N[p] = x, N[len - 1 - p] = -x, dfs(p + 1, a - 1, b + 1, 0, Ret * work(a, x));
		N[p] = x - 10, N[len - 1 - p] = 10 - x, dfs(p + 1, a - 1, b + 1, 1, Ret * work(a, x - 10));
	}
}

int main()
{
	scanf("%s", input), L = strlen(input);
	for (int i = 0;i <= L - 1;++i)
		D[i] = input[L - 1 - i] - '0';
	for (len = L;len <= 19;++len)
		memset(N, 0, sizeof(N)), dfs(0, len - 1, 0, 0);
	printf("%lld", Ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int K;
    cin >> K;

    vector<bool> check(K, false);
    ll cur = 0;
    for (int i=1; ; ++i) {
        cur = cur * 10 + 7;
        cur %= K;
        if (cur == 0) {
            cout << i << '\n';
            return;
        }
        if (check[cur]) {
            cout << -1 << '\n';
            return;
        }
        check[cur] = true;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

//ConvexHullTrick
typedef pair<int,int> pii;

struct CHT {
  vector<pii> deq;              // first * x + second
  int s,t;
  CHT(int n) {                  // n : クエリ数
    deq.resize(n);
    s=0, t=0;
  }
  void add(int a, int b) {      // a : 単調減少
    const pii p(a,b);
    while(s+1<t && check(deq[t-2],deq[t-1],p)) t--;
    deq[t++] = p;
  }
  int incl_query(int x) {            // x : 単調増加
    while(s+1<t && f(deq[s], x) >= f(deq[s+1], x)) s++;
    return f(deq[s], x);
  }
  int query(int x) {           // 条件なし
    int low = s-1, high = t-1;
    while(low+1<high) {
      int mid = (low+high)>>1;
      if (isright(deq[mid], deq[mid+1], x)) low = mid;
      else high = mid;
    }
    return f(deq[high], x);
  }
private:
  bool isright(const pii &p1, const pii &p2, int x) {
    return (p1.second-p2.second) >= x * (p2.first-p1.first);
  }
  bool check(const pii &p1, const pii &p2, const pii &p3) {
    return (p2.first-p1.first)*(p3.second-p2.second) >=
      (p2.second-p1.second)*(p3.first-p2.first);
  }
  int f(const pii &p, int x) {
    return p.first * x + p.second;
  }
};

int n, c;
int h[200010];
int dp[200010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> c;
    rep(i, 0, n) cin >> h[i];
    CHT cht(n);
    dp[0] = 0;
    cht.add(-h[0] * 2, h[0] * h[0] + c);
    rep(i, 1, n){
        dp[i] = h[i] * h[i] + cht.query(h[i]);
        cht.add(-h[i] * 2, h[i] * h[i] + c + dp[i]);
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[3000][3000];
char field[200][200];

ll dfs(int x,int y){
  if(y == 1)return 1;
  ll ans = 0;
  for(int i = 0;i <= x;i += y * y)ans += dfs(x-i,y-1);
  return ans;
}

int main(){
  while(cin >> n,n){
    print(dfs(n,17));
  }
  return 0;
}


Measured memory_bytes: 2992
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N,K;
    int l[55];
    cin >> N >> K;
    for (int i=0;i<N;i++) cin >> l[i];
    sort(l,l+N,greater<int>());

    int ret=0;
    for (int i=0;i<K;i++) ret+=l[i];

    cout << ret << endl;

    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

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


Measured memory_bytes: 256
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var s string
    fmt.Scan(&s)
    ans := "Good"
    if s[0]==s[1] || s[1]==s[2] || s[2]==s[3]{
        ans = "Bad"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


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

using namespace std;

int main(){
    int t, n;
    cin >> t >> n;
    if(!t){
        if(n == 100) cout << 101;
        else cout << n;
    }else if(t == 1){
        if(n == 100) cout << 10100;
        else cout << n * 100;
    }
    else if(n == 100) cout << 1010000;
    else cout << n * 10000;

    return 0;
}


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

 /// first: primo   second: exponente
 vector<pair<ll,ll> >Canon;
 int Gau[50];

void Prec(){

 int i;

 for(i=1;i<50;i++){
  Gau[i]=Gau[i-1]+i;
 }

 return;
}

int main(){

 ll N,Aux;
 cin>>N;
 ll i,j;

 Aux=N;

 if(Aux%2==0){
  Aux/=2;
  Canon.push_back({2,1});
   while(Aux%2==0){
    Aux/=2;
    Canon[Canon.size()-1].second+=1;
   }
 }

 if(Aux%3==0){
  Aux/=3;
  Canon.push_back({3,1});
   while(Aux%3==0){
    Aux/=3;
    Canon[Canon.size()-1].second+=1;
   }
 }

 if(Aux%5==0){
  Aux/=5;
  Canon.push_back({5,1});
   while(Aux%5==0){
    Aux/=5;
    Canon[Canon.size()-1].second+=1;
   }
 }

 for(i=6;i*i<=Aux;i+=6){

  if(Aux%(i+1)==0){
   Aux/=(i+1);
   Canon.push_back({i+1,1});
     while(Aux%(i+1)==0){
      Aux/=(i+1);
      Canon[Canon.size()-1].second+=1;
     }
  }

  if(Aux%(i+5)==0){
    Aux/=(i+5);
    Canon.push_back({i+5,1});
      while(Aux%(i+5)==0){
       Aux/=(i+5);
       Canon[Canon.size()-1].second+=1;
      }
  }
 }

 if(Aux>1)Canon.push_back({Aux,1});
 Prec();

 int Ans=0;

 for(i=0;i<Canon.size();i++){
  j=1;
   while(Canon[i].second>=Gau[j])j+=1;
   Ans+=j-1;
 }

 cout<<Ans;
}


Measured memory_bytes: 3612
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
#define endl "\n"
#define found true
#define infinity -1
#define not_found false
#define FOR(limit) for(int i = 0; i < limit; i++)
#define __FOR(limit) for(int j = 0; j < limit; j++)
#define __FOR__(limit) for(int k = 1; k <= limit; k++)
#define hello(a) a ? "Yes" : "No"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define F first
#define S second
// getline (cin, string);
typedef long long lld;
using namespace std;
void solving_f();
int main() {
    ios_base::sync_with_stdio(not_found);
//    cin.tie(0);
//    cout.tie(0);

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    solving_f();

    return not_found;
}
void solving_f() {
    int t;
    cin >> t;
    int count = not_found;
    string s;
    if(t >= 30)
        count = found;
    s = hello(count);
    cout << s << endl;
}


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

int main() {
  int n, k; cin >> n >> k;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin >> h[i];

  sort(h.begin(), h.end());

  long long int r = 0;
  for (int i=0; i<max(0, n-k); i++) r += h[i];
  cout << r << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define  N 100

int G[N][N];

int d[N],f[N],t =0,visited[N];

void visit(int i,int max){
  int j;
  visited[i] = 1;
  d[i] = ++t;
  for(j=0;j<max;j++){
    if(G[i][j] == 1 && visited[j]!=1){
      visit(j,max);
    }
  }

  f[i] = ++t;
}

int main () {
  int n,u,k,v,i,j;

  scanf("%d",&n);
  for(i=0;i<n;++i){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;++j){
      scanf("%d",&v);
      --v;
      G[u][v] = 1;
    }

  }
  for(i=0;i<n;++i){
    if(visited[i]!=1){
      visit(i,n);
    }
  }

  for(i=0;i<n;++i){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
}
  



Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        int offset = 'a' - 'A';
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if ('A' <= c && c <= 'Z') {
                System.out.print((char)(c + offset));
            } else if ('a' <= c && c <= 'z') {
                System.out.print((char)(c - offset));
            } else {
                System.out.print(c);
            }
        }
        System.out.println();
        scanner.close();
    }
}



Measured memory_bytes: 26744
n,k = map(int,input().split())
A = list(map(int,input().split()))
inner_count=0
other_count=0
for i in range(n):
  for j in range(n):
    if i==j or i>j:
      pass
    else:
      if A[i]>A[j]:
        inner_count+=1
for x in range(n):
  for y in range(n):
    if A[x]>A[y]:
      other_count+=1
inner_count = inner_count*k
other_count = other_count*(k*(k-1)//2)
print((inner_count+other_count)%(10**9+7))

Measured memory_bytes: 3188
using System;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];

        if (a + b >= 10)
        {
            Console.WriteLine("error");
        }
        else
        {
            Console.WriteLine(a + b);
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define in(j,n) for(j=0;j<n;j++)
#define inp(j,n) for(j=1;j<=n;j++)
#define lo(i,st,n) for(i=st;i<n;i++)
#define pb push_back
#define csbits(n) __builtin_popcount(n)
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
int main()
{
	ll i,j,l,t,n,W;
	cin>>n>>W;
	ll w[n],val[n];
	in(j,n)
		cin>>w[j]>>val[j];
	ll dp[n][W+1];
	in(i,n){
		in(j,W+1)
			dp[i][j]=0;
	}
	inp(j,W){
		if(j-w[0]>=0)
			dp[0][j]=val[0];
	}
	inp(i,n-1){
		inp(j,W)
			dp[i][j]=dp[i-1][j];
		inp(j,W){
			if(j-w[i]>=0)
				dp[i][j]=fmax(dp[i][j],dp[i-1][j-w[i]]+val[i]);
		}
	}
	ll ans=dp[0][W];
	in(i,n)
		ans=fmax(ans,dp[i][W]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 81724
#include <stdio.h>
int main(void){
    int x,i,n;
    scanf("%d",&n);
    for(i=1; i<=n; i++) {
        x = i;
        if(x %3 == 0) 
            printf(" %d",i);
        else if(x % 10 == 3)
            printf(" %d",i);
        else{
            while(x != 0) {
            x /=10;
                if(x % 10 == 3) {
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2064
n,a,b=map(int,input().split())
mod=10**9+7


def fac(n,a):
    ans=1
    for i in range(n,n-a,-1):
        ans*=i
        ans%=mod
    return ans%mod

def inv_fac(n):
    ans=pow(fac(n,n-1),mod-2,mod)
    return ans%mod



ans=pow(2,n,mod)-fac(n,a)*inv_fac(a)-fac(n,b)*inv_fac(b)
print(ans%mod-1)

Measured memory_bytes: 38512
#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, K;
  cin >> N >> K;
  ll d, A;
  vl snuke(N + 1, 0);
  rep(i, K){
    cin >> d;

    rep(j, d){
      cin >> A;
      snuke[A] = 1;
    }
  }

  ll cnt = 0;
  rep2(i, 1, N + 1){
    if(snuke[i] == 0) cnt++;
  }

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


Measured memory_bytes: 3636
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

diff = abs(A - (T - H[0] * 0.006))
index = 1
for idx, i in enumerate(H):
    temp = T - i * 0.006
    if abs(A - temp) < diff:
        diff = abs(A - temp)
        index = idx + 1
print(index)

Measured memory_bytes: 3064
n,m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
a,b = [],[]
for i in range(m):
  a1,b1 = [int(x) for x in input().split()]
  a.append(a1-1)
  b.append(b1-1)
ans = [1] * n
for i in range(m):
  if h[a[i]] < h[b[i]]:
    ans[a[i]] = 0
  elif h[a[i]] > h[b[i]]:
    ans[b[i]] = 0
  else:
    ans[a[i]] = 0
    ans[b[i]] = 0
c = 0
for i in range(n):
  if ans[i] == 1:
    c += 1
#print(ans)
print(c)

Measured memory_bytes: 22256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in) ;


        int n = sc.nextInt();

        int[] arr = new int[n] ;

        for (int i=0; i<n; i++) {
          arr[arr.length - i -1] = sc.nextInt() ;
        }

        for (int i=0; i<n; i++) {
          System.out.print(arr[i]);
          if(i!=n-1) System.out.print(" ");
          else System.out.print("\n");
        }

    }

}



Measured memory_bytes: 26216
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

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

	int n,x,MOD=1000000007;
	cin>>n>>x;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));

	vvi dp(n+1,vi(x+1));
	dp[0][x]=1;

	rep(i,n)rep(j,x+1)if(dp[i][j]){
		(dp[i+1][j]+=dp[i][j]*(n-1-i))%=MOD;
		(dp[i+1][j%in[n-1-i]]+=dp[i][j])%=MOD;
	}
	int out=0;
	rep(i,x+1)(out+=dp[n][i]*i)%=MOD;
	cout<<out<<endl;
}


Measured memory_bytes: 158592
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

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

    int ans=LLONG_MAX;
    for(int i=1;i<N;i++){
        int n=i;
        int k=N-i;
        int c=0;
        while(n!=0){
            c+=n%10;
            n/=10;
        }
        while(k!=0){
            c+=k%10;
            k/=10;
        }
        ans=min(ans,c);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3152
str = gets
ans = ""
str.length.times do |i|
  tmp = str[i..i]
  if "a" <= tmp && tmp <= "z"
    tmp = (tmp.ord - "a".ord + "A".ord).chr
  elsif "A" <= tmp && tmp <= "Z"
    tmp = (tmp.ord - "A".ord + "a".ord).chr
  end
  ans += tmp
end
print ans



Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int N;
	cin >> N;

	int count_minus = 0;
	vector<ll>num(N);
	ll sum = 0;
	REP(i, N) {
		cin >> num[i];
		if (num[i] < 0) count_minus++;
		num[i] = abs(num[i]);
		sum += num[i];
	}

	
	if (count_minus % 2 == 0) {
		cout << sum << endl;
	}
	else {
		ll minimum = INF;
		REP(i, N) {
			minimum = min(minimum, num[i]);
		}

		cout << sum - 2 * minimum << endl;

	}

	return 0;

}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    while(1){
        string number;
        cin >> number;
        
        if(number == "0") break;
        
        int sum = 0;
        for(int i = 0; i < number.size(); i++){
            int j = number[i] - '0';
            sum += j;
        }
        
        cout << sum << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef long long ll;

int main() {
	int n,m;
	ll count = 0;
	std::vector<int> xx ;
	std::cin >> n >> m;
	xx.resize(m);
	for (int i = 0; i < m; ++i)
	{
		std::cin >> xx[i];
	}
	if (n >= m)
	{
		std::cout << count << std::endl;
	}
	else {
			std::sort(xx.begin(), xx.end());
			
			std::vector<int> yy;
			yy.resize(m - 1);
			for (int i = 0; i < m - 1; i++)
			{
				yy[i] = xx[i + 1] - xx[i];
			}
			std::sort(yy.begin(), yy.end());

			for (int i = 0; i < (m - n); i++)
			{
				count += yy[i];
			}
		std::cout << count << std::endl;
	}
	return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int i;
    //入力
    int a,b;
    cin>>a>>b;
    //処理
    double c=a,d=b;
    //出力
    if((b-1)/(a-1)==(d-1)/(a-1))cout<<(b-1)/(a-1)<<endl;
    else cout<<1+(b-1)/(a-1)<<endl;
}

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

n,m,k = map(int,input().split())

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

num = [0]*n

for i in range(m):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    num[a-1] += 1
    num[b-1] += 1

edge = [[] for i in range(n)]

for i in range(k):
    c,d = map(int,input().split())
    edge[c-1].append(d-1)
    edge[d-1].append(c-1)


for i in range(n):
    cnt = size(i) - num[i] - 1
    for e in edge[i]:
        if same(e,i):
            cnt -= 1
    print(cnt,end=' ')


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

namespace ABC131A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var last = ' ';
            foreach (var i in input)
            {
                if (i == last)
                {
                    Console.WriteLine("Bad");
                    return;
                }
                last = i;
            }

            Console.WriteLine("Good");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  vector<vector<bool>>judge(3,vector<bool>(3,false));
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(a[i][j]==b){
          judge[i][j]=true;
        }
      }
    }
  }
  bool ans=false;
  for(int i=0;i<3;i++){
    if(judge[0][i]&&judge[1][i]&&judge[2][i]){
      ans=true;
    }
    if(judge[i][0]&&judge[i][1]&&judge[i][2]){
      ans=true;
    }
  }
  if(judge[0][0]&&judge[1][1]&&judge[2][2]){
    ans=true;
  }
  if(judge[0][2]&&judge[1][1]&&judge[2][0]){
    ans = true;
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  


Measured memory_bytes: 3520
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int l[2003];
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int lng = l[j] + l[i];
            ll ln = lower_bound(l, l + n, lng) - l - 1;
            ans += ln - j;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

N, D = map(int , input().split())
X = [list(map(int , input().split())) for _ in range(N)]
X = np.array(X)
cnt = 0
for i in range(N - 1):
    for j in range(i + 1 , N):
        dis = np.linalg.norm(X[i] - X[j])
        if dis.is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 22712
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e15;




int main()
{
    idfc;

    string s;
    cin>>s;

    int ans=0;

    int p=0;
    char e='a';


    for(char ii:s)
    {
        if(e==ii)
        {
            p++;
        }
        else{
            if(e=='R')ans=max(ans,p);
            p=1;
        }
        e=ii;
    }
    if(e=='R')ans=max(ans,p);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let s: String = read!(String);
    let c: Vec<_> = s.chars().collect();

    let mut ans = 1 << 30;
    for i in 0..(c.len() - 2) {
        let x = c
            .get(i..(i + 3))
            .unwrap()
            .iter()
            .map(|&y| y)
            .collect::<String>();
        let x: i32 = x.parse().unwrap();
        ans = min(ans, (x - 753).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
s = input()
t = input()
les = len(s)
let = len(t)
hoge = 0
if les < let:
  print('UNRESTORABLE')
  exit()
for i in range(les,let-1,-1):
  sa = s[i-let:i]
  for j in range(len(sa)):
    if sa[j] != t[j] and sa[j] != '?':
      break
    if j == len(sa)-1:
      hoge += 1
  if hoge == 1:
    sb = s[:i-let] + t + s[i:]
    ans = ''
    for v in sb:
      if v == '?':
        ans += 'a'
      else:
        ans += v
    print(ans)
    exit()
print('UNRESTORABLE')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define reps(i, s, n) for(int i = (s); i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--)
#define INF ~(1 << 31)
#define INFL ~(1LL << 63)

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> d(n);
    rep(i, n){
        cin >> d[i].first >> d[i].second;
    }
    int count = 0;
    bool ans = false;
    rep(i, n){
        if(d[i].first == d[i].second) count++;
        else count = 0;
        if(count == 3){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  int total = r*100+g*10+b;
  if(total % 4 == 0){
    cout << "YES";
  }else{
    cout << "NO";
  }
  cout << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
table = {0: 0}
buf = 0
cnt = 0
for i in range(n):
    buf = (buf + a[i]) % m
    if buf in table:
        cnt += table[buf]
        table[buf] += 1
    else:
        table[buf] = 1
print(cnt + table[0])

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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<long long int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    cin >> c.at(i);
    for(int j=0;j<m;j++)
      cin >> a.at(i).at(j);
  }
  
  vector<int> r(n+1,1);
  for(int i=1;i<n+1;i++) r.at(i)=r.at(i-1)*2;
  
  long long int money=10000000000;
  
  for(int i=0;i<r.at(n);i++){//iは各参考書を買う/買わない
    vector<int> y(m);
    long long int price=0;
    for(int j=0;j<n;j++){//各参考書について
      if(i/r.at(j)%2){//その参考書を買うなら理解度と代金を足す
        for(int l=0;l<m;l++) y.at(l)+=a.at(j).at(l);
        price+=c.at(j);
      }
    }
    int g=1;
    for(int j=0;j<m;j++){//各アルゴリズムの理解度
      g*=(y.at(j)>=x);
    }
    if(g){
      money=min(money,price);
    }
  }
  if(money==10000000000) money=-1;
  cout << money << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

typedef struct label
{
    int top;    //1
    int front;  //2
    int right;  //3
    int left;   //4
    int back;   //5
    int bottom; //6
} Dice;

void diceroll(Dice *d, const char *dir)
{
    while (*dir)
    {
        int tmp;
        switch (*dir)
        {
        case 'E':
        {
            tmp = d->top;
            d->top = d->left;
            d->left = d->bottom;
            d->bottom = d->right;
            d->right = tmp;
            break;
        }
        case 'N':
        {
            tmp = d->top;
            d->top = d->front;
            d->front = d->bottom;
            d->bottom = d->back;
            d->back = tmp;
            break;
        }
        case 'S':
        {
            tmp = d->top;
            d->top = d->back;
            d->back = d->bottom;
            d->bottom = d->front;
            d->front = tmp;
            break;
        }
        case 'W':
        {
            tmp = d->top;
            d->top = d->right;
            d->right = d->bottom;
            d->bottom = d->left;
            d->left = tmp;
            break;
        }
        }
        dir++;
    }
}

int main(void)
{
    Dice one;
    char direction[101]; //方位
    scanf("%d %d %d %d %d %d", &one.top, &one.front, &one.right, &one.left, &one.back, &one.bottom);
    scanf("%s", direction);
    diceroll(&one, direction);
    printf("%d\n", one.top);
    return 0;
}



Measured memory_bytes: 2100
x1,y1,x2,y2 = map(int,input().split(" "))
flag = 0
if x2 >= x1 and y2 >= y1:
  flag = 1
elif x2 >= x1 and y2 < y1:
  flag = 2
elif x2 < x1 and y2 >= y1:
  flag = 3
else:
  flag = 4
if flag == 1:
  x3 = x2-(y2-y1)
  y3 = y2+(x2-x1)
  x4 = x1-(y2-y1)
  y4 = y1+(x2-x1)
elif flag == 2:
  x3 = x2+(y1-y2)
  y3 = y2+(x2-x1)
  x4 = x1+(y1-y2)
  y4 = y1+(x2-x1)
elif flag == 3:
  x3 = x2-(y2-y1)
  y3 = y2-(x1-x2)
  x4 = x1-(y2-y1)
  y4 = y1-(x1-x2)
else:
  x3 = x2+(y1-y2)
  y3 = y2-(x1-x2)
  x4 = x1+(y1-y2)
  y4 = y1-(x1-x2)
print(x3,y3,x4,y4)

Measured memory_bytes: 3064
r, c = gets.split.map(&:to_i)

sums = Array.new(c+1).map{0}

r.times do |i|
  nums = gets.split.map(&:to_i)
  nums << nums.sum
  nums.each_with_index do |num, i|
    sums[i] += num
  end

  puts nums.join(" ")
end

puts sums.join(" ")



Measured memory_bytes: 7000
let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let () =
  Scanf.scanf "%d" @@ fun n ->
  let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun x -> x)) in
  let s = Array.init (2*n-1) (fun i ->
    Array.init n (fun j -> s.(i mod n).[j mod n])) in
  for_fold 0 n 0 (fun c i ->
    let sym =
      for_fold 0 (n*n) true (fun b j ->
        b && s.(i + j/n).(j mod n) = s.(i + j mod n).(j/n))
    in c + if sym then n else 0)
  |> Printf.printf "%d\n"

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  vector<int> n(3);
  int k;
  cin >> n[0] >> n[1] >> n[2] >> k;
  sort(all(n));
  for (int i = 0; i < k; i++) {
    n[2] *= 2;
  }
  cout << accumulate(all(n), 0) << endl;
  return 0;
}

Measured memory_bytes: 256