akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=55,maxv=55;
long long f[maxn][maxn][maxn*maxv],N,a[maxn],A;
int main(){
	//freopen("in","r",stdin);
	N=read();A=read();
	for(int i=1;i<=N;i++)
		a[i]=read();
	f[0][0][0]=1;
	for(int i=1;i<=N;i++)
		for(int j=0;j<=i;j++)
			for(int k=0;k<maxn*maxv;k++){
				f[i][j][k]+=f[i-1][j][k];
				if(k>=a[i]&&j)
					f[i][j][k]+=f[i-1][j-1][k-a[i]];
			}
	long long ans=0;
	for(int i=1;i<=N;i++)
		if(i*A<maxn*maxv)
			ans+=f[N][i][i*A];
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 65792
def main():
    N,M,X,Y = map(int,input().split())
    x_s = list(map(int,input().split()))
    y_s = list(map(int,input().split()))

    ok = False
    for z in range(X+1,Y+1):
        if z > max(x_s) and z <= min(y_s):
            ok = True
            break

    print("No War" if ok else "War")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	n = n - n%3
	ans := 0
	for i := 0; i < n; i++ {
		if string(s[i]) == "A" && string(s[i+1]) == "B" &&
			string(s[i+2]) == "C" {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(void)
{
	int a,b;
	while(cin>>a>>b)
	{
		if(a==1)
		a+=13;
		if(b==1)
		b+=13;
		if(a>b)
		cout<<"Alice"<<endl;
		else if(a<b)
		cout<<"Bob"<<endl;
		else
		cout<<"Draw"<<endl;
	}
	return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	int n;
	cin>>n;
	cout<<(n^1)<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;

template<typename X, typename Y> ostream &operator<< (ostream &fout, const pair<X, Y> &p)
{ fout << '{' << p.first << ", " << p.second << "} "; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e3 + 5;

bool chk(ll a1, ll a2, ll a3, ll a4, ll a5, ll a6)
{
    ll b1 = llabs(a1 - a2);
    ll b2 = llabs(a3 - a4);
    ll b3 = llabs(a5 - a6);
    if (b1 != b2 || b1 != b3) return false;
    return true;
}

int main()
{
    ll c[3][3];
    for (ll i = 0; i < 3; i++)
        for (ll j = 0; j < 3; j++)
            cin >> c[i][j];

    if (!chk(c[0][0], c[0][1], c[1][0], c[1][1], c[2][0], c[2][1])) { cout << "No" << endl; exit(0); }
    if (!chk(c[0][0], c[0][2], c[1][0], c[1][2], c[2][0], c[2][2])) { cout << "No" << endl; exit(0); }
    if (!chk(c[0][1], c[0][2], c[1][1], c[1][2], c[2][1], c[2][2])) { cout << "No" << endl; exit(0); }

    if (!chk(c[0][0], c[1][0], c[0][1], c[1][1], c[0][2], c[1][2])) { cout << "No" << endl; exit(0); }
    if (!chk(c[0][0], c[2][0], c[0][1], c[2][1], c[0][2], c[2][2])) { cout << "No" << endl; exit(0); }
    if (!chk(c[1][0], c[2][0], c[1][1], c[2][1], c[1][2], c[2][2])) { cout << "No" << endl; exit(0); }

    cout << "Yes" << endl;

    return 0;
}


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

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);
    int n;
    scanf("%d",&n);


    ll ans = 0;
    int a=0;
    maxs(a,x);
    maxs(a,y);
    maxs(a,z);
    ans+=x+y+z-a;
    rep(i,n){
        a*=2;
    }
    ans+=a;

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


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

int main(){
	int n,m;
	cin >> n >> m;
	int ans = 0;

	for(int i = 0; i < m; i++){
		int temp;
		cin >> temp;
		ans += temp;
	}

	if(n < ans) cout << -1  << endl;
	else cout <<   n - ans << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = sc.nextInt()
    val t = sc.nextInt()
    println(problem176a(n, x, t))
}

fun problem176a(n: Int, x: Int, t: Int): Int {
    var sum = 0
    var time = 0
    while (sum < n) {
        sum += x
        time += t
    }
    return time
}

Measured memory_bytes: 36460
import collections

n,m=map(int,input().split())
# a = []
# b = []
temp = []
for i in range(m):
    tempa,tempb = map(int,input().split())
    temp.append(tempa)
    temp.append(tempb)
temp.sort()
temp_count = collections.Counter(temp)
# print(temp_count)
for i in range(1,n+1):
    print(temp_count[i])


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> P;
bool pairCompare(const P& x, const P& y)
{
    if(x.first.compare(y.first)==0){
        return x.second > y.second;
    }
    return x.first < y.first;
}
int main() {
    int n;
    vector<P> v, v_sort;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        P p;
        cin >> p.first >> p.second;
        v.push_back(p);
        v_sort.push_back(p);
    }
    sort(v_sort.begin(), v_sort.end(), pairCompare);
    for(P p : v_sort){
        for (int i = 0; i < n; ++i) {
            if(v.at(i).first!=p.first || v.at(i).second!=p.second){
                continue;
            }
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000009
#define MAX 500005;
#define PI 3.14159265358979323846

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }


int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        ll n, c;
        cin >> n >> c;
        ll w[n], v[n];
        REP(i, 0, n) cin >> w[i] >> v[i];
        ll dp[c + 1][n + 1];
        mem(dp, 0);
        REP(i, 1, c + 1)
        {
            REP(j, 1, n + 1) {
                dp[i][j] = dp[i][j - 1];
                if (w[j - 1] <= i) {
                    dp[i][j] = max(dp[i][j], v[j - 1] + dp[i - w[j - 1]][j - 1]);
                }
            }
        }
        cout << dp[c][n];
    }
    return 0;
}



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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int solve(int N) {
    set<string> prev = {""};
    set<string> ans;
    for (int i = 0; i < N; ++i) {
        ans = {};
        for (const auto s : prev) {
            set<char> cs;
            for (int j = 0; j < s.size(); ++j) {
                ans.insert(s + s[j]);
                cs.insert(s[j]);
            }
            for (char c = 'a'; c <= 'z'; ++c) {
                if (cs.find(c) == cs.end()) {
                    ans.insert(s + c);
                    break;
                }
            }
        }
        swap(prev, ans);
    }
    for (const auto s : prev) {
        cout << s << endl;
    }
}

int main() {
    int N;
    cin >> N;
    solve(N);
}

Measured memory_bytes: 14720
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
	
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,ans,a[N],vis[N],vis2[N],tot,tot2;
pa z[N],z2[N];
signed main(){
	n=read();
	F(i,1,n) a[i]=read();
	F(i,1,n/2){
		vis[a[i*2-1]]++;
		vis2[a[i*2]]++;
	}
	F(i,1,100000){
		if (vis[i]) z[++tot]=mp(vis[i],i);
		if (vis2[i]) z2[++tot2]=mp(vis2[i],i);
	}
	sort(z+1,z+tot+1);sort(z2+1,z2+tot2+1);ans=n;
	D(i,tot,1){
		if (z[i].se!=z2[tot2].se) ans=min(ans,n-z[i].fi-z2[tot2].fi);
		else ans=min(ans,n-z[i].fi-z2[tot2-1].fi);
	}
	wrn(ans);
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int MOD = 1000000007;
const int maxN = 1000005;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n  ;
	int a;
	vector<int> count(n + 1);
	for (int i = 1; i < n; i++) {
		cin >> a ;
		++count[a];
	}
	for (int i = 1; i < n; i++) {
		cout << count[i] << "\n";
	}
	cout << 0 << "\n";
	
	return 0;
}



Measured memory_bytes: 4000
#include<string>
#include <iostream>
#include<vector>
#include <algorithm>
#include<queue>
#include<map>
#define T long long

int main(void){
	unsigned T result=0;
	unsigned T dp[2019][2]={0};
	std::string s;
	std::getline(std::cin, s);
	dp[static_cast<int>(s[0]-'0')][0]=1;
	//dp[0][0]=1;
	int size = s.size();
	for(int i=1;i<size;i++){
		int aj=static_cast<int>(s[i]-'0');
		for(int j=0;j<2019;j++){
			dp[(j*10+aj)%2019][i%2]=dp[j][(i-1)%2];
		}
		dp[aj][i%2]++;
		result += dp[0][i%2];
	}
	std::cout << result<<std::endl;
}


Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main(){
  while(1){
    int b, r, g, c, s, t, ans = 100;
    cin >> b >> r >> g >> c >> s >> t;
    if(b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0) break;
    ans += b * 15;
    ans += r * 15;
    ans += g * 7;
    ans += c * 2;
    ans += b * 5 * 15 + r * 3 * 15;

    ans -= (t - s - b * 5 - r * 3) * 3;
    ans -= (b * 5 + r * 3) * 2;
    cout << ans << endl;

  }
}

Measured memory_bytes: 3016
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	int i,j;
	char str[105][105];
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++)
	{
			scanf("%s",&str[i]);
	}
	for(j=0;j<=b+1;j++)
	{
		printf("#"); 
	}
	printf("\n"); 
	for(i=0;i<a;i++)
	{
		printf("#%s#\n",str[i]);
	}
	for(j=0;j<=b+1;j++)
	{
		printf("#");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let x = int();
    println!("{}", if x < 1200 {"ABC"} else {"ARC"})
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  bool ans = false;
  for(int i=0; i<s.size(); i++){
    if(s == t){
      ans = true;
      break;
    }
    s = s.back() + s.substr(0,s.size()-1);
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
 
 int a[]={4, 9, 4};

 int calc(vi v){
 	int ret = 0;
 	for(int i = 1; i <= 3; i++){
 		ret += v[i] * a[i - 1];
 	}
 	return ret;
 }

int main(){
	int n;
	while(cin>>n && n > 0){
		vii v(n, vi(5,0));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 4; j++) cin>>v[i][j];
			v[i][4] = calc(v[i]);
		}
		vi m(5,0);
		for(int i = 1; i < 5; i++) cin>>m[i];
		vi ans;
		for(int i = 0; i < n; i++){
			for(int j = 1; j < 5; j++){
				if(v[i][j] > m[j]) break;
				if(j == 4) ans.pb(v[i][0]);
			}
		}
		if(ans.size()==0)cout<<"NA"<<endl;
		else{
			for(int i = 0; i < ans.size(); i++){
				cout<<ans[i]<<endl;
			}
		}
	}
}

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

#define MAX_H (1000)
#define MAX_W (1000)
#define NUM_MOD (1000000007)
#define SIZE_BUF (30)

int main() {
  // read inputs
  int H, W;
  char ass[MAX_H][MAX_W + 1], buf[SIZE_BUF];
  scanf("%d %d", &H, &W);
  fgets(buf, SIZE_BUF, stdin);
  for (int i = 0; i < H; i++) {
    scanf("%s", ass[i]);
    fgets(buf, SIZE_BUF, stdin);
    // printf("%s\n", ass[i]);
  }

  // solve dp
  int dpss[MAX_H][MAX_W];
  // initialize
  dpss[0][0] = 1;
  // update
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i != 0 || j != 0) {
        int dp = 0;
        if (i - 1 >= 0 && ass[i - 1][j] == '.') {
          dp = (dp + dpss[i - 1][j]) % NUM_MOD;
        }
        if (j - 1 >= 0 && ass[i][j - 1] == '.') {
          dp = (dp + dpss[i][j - 1]) % NUM_MOD;
        }
        dpss[i][j] = dp;
      }
    }
  }
  printf("%d\n", dpss[H - 1][W - 1]);
}

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

int main()
{
    char s[5];
    scanf("%s",s);
    for(int i=0;i<8;i++)
    {
        int ans=s[0]-'0';
        for(int j=1;j<1<<3;j<<=1)
        {
            if(i&j) ans+=s[(int)log2(j)+1]-'0';
            else ans-=s[(int)log2(j)+1]-'0';
        }
        if(ans==7)
        {
            printf("%d",s[0]-'0');
            for(int j=1;j<1<<3;j<<=1)
            {
                if(i&j) printf("%c%d",'+',s[(int)log2(j)+1]-'0');
                else printf("%c%d",'-',s[(int)log2(j)+1]-'0');
            }
            printf("=7\n");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

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


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = list()
for i in range(N):
    AB.append(list(map(int, input().split())))

AB = sorted(AB)

drink = 0
money = 0
iter = 0
while drink < M:
    add = min(AB[iter][1], M-drink)
    drink += add
    money += add*AB[iter][0]
    iter += 1

print(money)




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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++)
    {
        int s = i % 10, t = i / 10000 % 10;
        int u = i / 10 % 10, v = i / 1000 % 10;
        if (s == t && u == v)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
# D (Cheat) 

n = int(input())

ans = 0
for j in range(1,n+1):
#     for i in range(1,n+1):
#         if i % j == 0:
#             ans += i
    _tmp = n//j
    ans += j * _tmp * (_tmp+1) // 2
    
print(ans)
            

Measured memory_bytes: 63168
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

int col[] = {0,-1,0,1,1,1,-1,-1};
int row[] = {-1,0,1,0,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};

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

    int n,k;
    cin >> n >> k;

    vi hight(n);
    vll cost(n,INF);

    cin >> hight[0];
    cost[0] = 0;

    for(int i = 1 ; i < n ; ++i)
    {
        cin >> hight[i];

        if(i > k)
        {
            for(int j = i-1; j >= i-k ; --j)
            {
                ll one = abs(hight[i]-hight[j]);

                cost[i] = min(one+cost[j],cost[i]);
            }
            //cout << i << " " << cost[i] << endl;
        }
        else
        {
            cost[i] = abs(hight[0]-hight[i]);
        }
    }

    cout << cost[n-1];

    return 0;
}


Measured memory_bytes: 4452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll> p1;

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

    int n;
    cin >> n;
    cout << 3 * n*n << endl;
    return 0;
}


Measured memory_bytes: 256
/* ???????????????10?????????????????????????????????????????????3???????????????????????????????????°?????? */

#include <stdio.h>

int main(void) {
  int height[10];
  int i;
  for(i = 0;i < 10;i++)  scanf("%d", &height[i]);
  int temp,j,k;
  temp = 0;
  for(j = 0;j < 10;j++) {
    for(k = 0;k < 10;k++) {
      if(height[j] > height[k]) {
	temp = height[j];
	height[j] = height[k];
	height[k] = temp;
	temp = 0;
      }
    }
  }
  int l;
  for(l = 0;l < 3;l++) printf("%d\n", height[l]);
  return 0;
}

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


using namespace std;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-8;
const ll MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 10001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll dp[401][401];
int a[5001];
int b[5001];

ll mul(ll a, ll b) {
    return a * b % MOD;
}

ll pw[500][500];

signed main() {
#ifdef zxc
    mt19937 mt(228);
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
//            freopen("", "r", stdin);
//        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(10);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    int n, c;
    cin >> n >> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; ++i) {
        for (int x = a[i]; x <= b[i]; ++x) {
            ll cur_pw = 1;
            for (int p = 0; p <= c; ++p) {
                pw[i][p] += cur_pw;
                if (pw[i][p] >= MOD) {
                    pw[i][p] -= MOD;
                }
                cur_pw *= x;
                cur_pw %= MOD;
            }
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int sum = 0; sum <= c; ++sum) {
            for (int j = 0; j + sum <= c; ++j) {
                dp[i][sum + j] += mul(dp[i - 1][sum], pw[i][j]);
                if (dp[i][sum + j] >= MOD) {
                    dp[i][sum + j] -= MOD;
                }
            }
        }
    }
    cout << dp[n][c];
    auto end = chrono::steady_clock::now();
    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



Measured memory_bytes: 3072
import java.util.Scanner;

class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            int N = sc.nextInt();
            if (N == 0) break;
            int[] page = new int[N];
            for (int i = 0; i < N; ++i) {
                page[i] = sc.nextInt();
            }
            int start = 0;
            for (int i = 1; i < N; ++i) {
                if (page[i] == page[i - 1] + 1) {
                    continue;
                }
                if (i == start + 1) {
                    System.out.print(page[start] + " ");
                } else {
                    System.out.print(page[start] + "-" + page[i - 1] + " ");
                }
                start = i;
            }
            if (start == N - 1) {
                System.out.println(page[start]);
            } else {
                System.out.println(page[start] + "-" + page[N - 1]);
            }
        }
    }
}



Measured memory_bytes: 34240
N = int(input())
n_four, n_two, n_other = 0, 0, 0
for ai in map(int, input().split()):
    if ai % 4 == 0:
        n_four += 1
    elif ai % 2 == 0:
        n_two += 1
    else:
        n_other += 1

if n_two == 0 and n_four + 1 >= n_other:
    print('Yes')
elif n_two > 0 and n_four >= n_other:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11480
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
using namespace std;
long long n,a[100009],ans,now;
int main()
{ 
	cin>>n;
	for (int i=1;i<=n;++i)
		cin>>a[i];
	a[++n]=0;
	int now=0;
	for (int i=1;i<=n;++i)
	{
		ans+=abs(a[i]-now);
		now=a[i];
	}
	for (int i=1;i<n;++i)
	{
		cout<<ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double a,b,x,h0;
int main()
{
    scanf("%lf%lf%lf",&a,&b,&x);
    if (a * a * b / 2 > x)
    {
        h0 = 2 * x / a / b;
        printf("%.10lf",90 - atan(h0 / b) * 180 / (acos(-1)));
    }
    else
    {
        h0 = 2 * b - 2 * x / (a * a);
        printf("%.10lf",90 - atan(a / h0) * 180 / (acos(-1)));
    }
    return 0;
}

Measured memory_bytes: 1020
#include <stdio.h>

int main()
{
	int W,H,x,y,r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if( x + r > W ||
    	    x - r < 0 ||
	    y + r > H ||
	    y - r < 0 )
	{
		printf("No\n");	
	}
	else
	{
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private static int MOD = 1000000007;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a > b + W) {
			System.out.println(a - (b + W));
		} else if (b < a + W) {
			System.out.println(0);
		} else {
			System.out.println(b - (a + W));
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21204
#include <stdio.h>

int main() {
  int n, num;
  float inverse = 0, one = 1.0f;
  scanf("%d", &n);
  while(n--) {
    scanf("%d", &num);
    inverse += (float)(one / (float)num);
  }
  printf("%f", one / inverse);
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	int a[2][n];
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n; j++){
			cin>>a[i][j];
			if(i == 0 && j != 0)a[i][j] += a[i][j - 1];
			if(i == 1 && j == 0)a[i][j] += a[i - 1][j];
			if(i == 1 && j != 0)a[i][j] += max(a[i][j - 1], a[i - 1][j]);
		}
	}
	cout<<a[1][n - 1]<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//n個のコマの担当範囲をどう区切るかの問題に帰着できる
//範囲を決めることは、その右端から次の担当コマまでの区間をカウントしなくてよくすることと同義
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i,m) cin >> x[i];

    int ans=0;
    vector<int> d(m-1);
    sort(all(x));
    rep(i,m-1) d[i]=x[i+1]-x[i];
    sort(all(d));
    //距離dが大きい上位n-1個のdはカウントしなくて良い
    rep(i,m-n) ans += d[i];

    cout << ans << endl;


}

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

using namespace std;

int main()
{
  int N;
  int p[4] = {0};
  int t[4] = {0};
  cin>>N;
  for(int i = 0;i < 4;++i){
    int s;
    cin>>s;
    p[i] = s;
  }
  for(int i = 0;i < 4;++i){
    int s;
    cin>>s;
    t[i] = s;
  }
  
  int ans = 100000;
  for(int i = 0;(N + t[0]) > t[0] * i;++i){
    for(int j = 0;(N + t[1]) - t[0] * i > t[1] * j || j == 0;++j){
      for(int k = 0;(N + t[2]) - (t[0] * i + t[1] * j) > t[2] * k || k == 0;++k){
        for(int l = 0;(N + t[3]) - (t[0] * i + t[1] * j + t[2] * k) > t[3] * l || l == 0;++l){
          if(N <= i*t[0] + j*t[1] + k*t[2] + l*t[3]){
            int temp = i*p[0] + j*p[1] + k*p[2] + l*p[3];
            ans = min(ans,temp);
            //cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<temp<<endl;
          }
        }
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
int mat[101][101];

int main(){
  int n;
  cin >> n;
  for (int i=0;i<n;i++){
    int id,k;
    cin >> id >> k;
    for (int j=0;j<k;j++){
      int temp;
      cin >> temp;
      mat[id][temp] = 1;
    }
  }
  for (int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if (j!=1)
        cout << " ";
      cout << mat[i][j];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	factors := Factorization(M)
	ans := 1
	for i := 0; i < len(factors); i++ {
		p := factors[i][1]
		ans *= ModCombination(N-1+p, p)
		ans %= Mod
	}
	fmt.Println(ans)
}

func Factorization(n int) [][]int {
	res := [][]int{}
	for i := 2; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		cnt := 0
		for n%i == 0 {
			n /= i
			cnt++
		}
		res = append(res, []int{i, cnt})
	}
	if n != 1 {
		res = append(res, []int{n, 1})
	}
	return res
}

const Mod = int(1e9) + 7

func ModAdd(a, b int) int  { return ((Mod + a%Mod) + (Mod + b%Mod)) % Mod }
func ModMul(a, b int) int  { return (Mod + a%Mod) * (Mod + b%Mod) % Mod }
func ModInverse(n int) int { return ModPow(n, Mod-2) }
func ModDiv(a, b int) int  { return a * ModInverse(b) }
func ModPow(a, b int) (x int) {
	for x = 1; b > 0; b >>= 1 {
		if b&1 == 1 {
			x = x * a % Mod
		}
		a = a * a % Mod
	}
	return
}
func ModFactorial(n int) int      { return fac[n] }
func ModPermutation(n, r int) int { return fac[n] * finv[n-r] % Mod }
func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 5 * 1e5
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for 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
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 14032
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+7;
char s[N];
int main()
{
	int n, a, b, c, d;
	scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s+1);
	for(int i = a+1; i <= c; i++)
	{
		if(s[i]=='#'&&s[i+1]=='#')
		{
			puts("No");
			return 0;
		}
	}
	for(int i = b+1; i <= d; i++)
	{
		if(s[i]=='#'&&s[i+1]=='#')
		{
			puts("No");
			return 0;
		}
	}
	if(c>d)
	{
		for(int i = b; i <= d; i++)
		{
			if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')
			{
				puts("Yes");
				return 0;
			}
		}
		puts("No");
		return 0;
	}
	/*if(c==d+1&&s[d-1]=='#'&&(s[b+1]=='#'||s[b-1]=='#'))
	{
		puts("No");
		return 0;
	}*/
	puts("Yes");
	return 0;
}


Measured memory_bytes: 384
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){
            long n = ILongs()[0];
            long[] a = ILongs();

            HashSet<long>[] yakusu = new HashSet<long>[n]; //添え字注意

            for(long i=0;i<n;i++){
                yakusu[i] = new HashSet<long>();
                for(long j=1;j<=(long)Sqrt(n);j++){
                    if((i+1)%j==0){
                        yakusu[i].Add(j);
                        yakusu[i].Add((i+1)/j);
                    }
                }
            }

            bool[] odd = new bool[n];

            List<long> ireta = new List<long>();

            for(long i=n-1;i>-1;i--){
                if(odd[i]!=(a[i]==1)){
                    ireta.Add(i+1);
                    foreach(long ireru in yakusu[i]){
                        odd[ireru-1] = !odd[ireru-1];
                    }
                }
            }

            List<string> ans = new List<string>();
            foreach(long ir in ireta){
                ans.Add(ir.ToString());
            }
            Console.WriteLine(ireta.Count);
            Console.WriteLine(String.Join(" ",ans));
            
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}


Measured memory_bytes: 179852
// cand <genesis?>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll base = 7;
const ll N = 1e6 + 9;
const ll inf = 1000100009;
typedef pair<ll,ll> LL;

string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("test.INP", "r", stdin);
    cin>>s;
    if (s == "ABC") cout<< "ARC";
    else cout << "ABC";
}


Measured memory_bytes: 3568
#include <stdio.h>

int fun1(int price1, int basicPrice, int addLitter, int addPrice, int usedLitter);

int main()
{
	int A,B,C,D,P;
	scanf("%d %d %d %d %d",&A,&B,&C,&D,&P);
	printf("%d\n",fun1(A,B,C,D,P));
	return 0;
}

int fun1(int price1, int basicPrice, int addLitter, int addPrice, int usedLitter)
{
	int pay, price2=0;
	
	price1 = price1*usedLitter;
	
	if(usedLitter>addLitter)
	{
		price2 = basicPrice + (usedLitter-addLitter) * addPrice;
	}
	else
	{
		price2 = basicPrice;
	}
	pay = price1<price2 ? price1 : price2;
	return pay;
}

Measured memory_bytes: 596
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = DateTime.Parse(Console.ReadLine());
            if (N <= new DateTime(2019, 4, 30)) Console.WriteLine("Heisei");
            else Console.WriteLine("TBD");
        }
    }
}


Measured memory_bytes: 13792
while 1:
    n=int(input())
    if n==0:break
    a=0
    s=input().split()
    for i in range(0,len(s)-1,2):
        s[i]+=s[i+1]
        if(('lu' in s[i] and 'ru' in s[i])or('ld' in s[i] and 'rd' in s[i])):a+=1
    print(a)

Measured memory_bytes: 7704
#include "stdio.h"
#include "string.h"

int main()
{
  char s1[12];
  fgets (s1,12,stdin);
  int l = strlen(s1)-1;
  char s2[l+1];
  fgets (s2,l+1,stdin);
  int i,c=0;
  for (i=0; i<l; i++)
    {
      if (s1[i] == s2[i])
        c=0;
      else
        {
          c=1;
          break;
        }
    }
  if (c==0)
    printf ("Yes\n");
  else
    printf ("No\n");
  return 0;
}


Measured memory_bytes: 1512
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<pair<int, char>> P(N * 2);
  for (int i = 0; i < N; i++){
    P[i] = make_pair(a[i], 'a');
  }
  for (int i = N; i < N * 2; i++){
    P[i] = make_pair(b[i - N], 'b');
  }
  sort(P.begin(), P.end());
  long long ans = 1;
  int cnt = 0;
  for (int i = 0; i < N * 2; i++){
    if (P[i].second == 'a'){
      if (cnt < 0){
        ans *= -cnt;
        ans %= MOD;
      }
      cnt++;
    } else {
      if (cnt > 0){
        ans *= cnt;
        ans %= MOD;
      }
      cnt--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct UnionFind {
#define rep(i,n) for (int i=0; i < int(n); i++)
  vector<int> par;
  vector<int> dw;
  vector<int> sizes;

  UnionFind(int n) : par(n), dw(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    int xp = find(par[x]);
    dw[x] += dw[par[x]];
    return par[x] = xp;
  }

  void unite(int x, int y, int w) {
    int xp = find(x);
    int yp = find(y);

    if (xp == yp) return;

    if (sizes[xp] >= sizes[yp]) {
        par[yp] = xp;
        dw[yp] = dw[x] - dw[y] + w;
        //dw[y] += dw[x] - dw[y] + w;
        sizes[x] += sizes[y];
    } else {
        swap(x, y);
        swap(xp, yp);
        par[yp] = xp;
        dw[yp] = dw[x] - dw[y] - w;
        //dw[y] += dw[x] - dw[y] - w;
        sizes[x] += sizes[y];
    }

  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return sizes[find(x)];
  }
#undef rep
};

int main()
{
    for (;;) {
        int n, m;
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0)
            break;

        UnionFind uf(n);
        for (int i = 0; i < m; ++i) {
            //for (int i = 0; i < n; ++i) printf("%d: par=%d, dw=%d\n", i+1, uf.par[i]+1, uf.dw[i]);
            char c;
            scanf(" %c", &c);
            if (c == '!') {
                int a, b, w;
                scanf("%d %d %d", &a, &b, &w);
                uf.unite(a - 1, b - 1, w);
            } else /* if (c == '?') */ {
                int a, b;
                scanf("%d %d", &a, &b);
                if (uf.same(a - 1, b - 1))
                    printf("%d\n", uf.dw[b - 1] - uf.dw[a - 1]);
                else
                    printf("UNKNOWN\n");
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2104
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int sx = sc.nextInt();
    int sy = sc.nextInt();
    int tx = sc.nextInt();
    int ty = sc.nextInt();
    int p = tx - sx;
    int q = ty - sy;
    String r = "";
    for(int i = 0; i < p; i++) {
      r += "R";
    }
    String r2 = r + "R";

    String u = "";
    for(int i = 0; i < q; i++) {
      u += "U";
    }
    String u2 = u + "U";

    String l = "";
    for(int i = 0; i < p; i++) {
      l += "L";
    }
    String l2 = l + "L";

    String d = "";
    for(int i = 0; i < q; i++) {
      d += "D";
    }
    String d2 = d + "D";

    String ans = r + u + l + d2 + r2 + u2 + "L" + "U" + l2 + d2 + "R";
    System.out.println(ans);
  }
}

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


int main(){
    int n;
    cin >> n;
    int a[2][n];
    rep(i,2) rep(j,n) cin >> a[i][j];

    int dp[2][n];
    dp[0][0] = a[0][0];
    rep(j,n-1) dp[0][j+1] = dp[0][j] + a[0][j+1];
    dp[1][0] = a[0][0] + a[1][0];
    rep(j,n) dp[1][j+1] = max(dp[0][j+1], dp[1][j]) + a[1][j+1];

    cout << dp[1][n-1] << endl;
}


Measured memory_bytes: 256
# 方針
# 逆順でUnionfind木を作成していき、iの橋を追加したとき解消された不便さを計算していく

class UnionFindTree():
    # Union find tree
    # 2つの効率化　経路圧縮、ランク
    # つなげることはできるか分離することはできないので、木をつなげる方向に利用する
    # 
    def __init__(self, node_size):
        # node_num: 全体のノード数
        # parent: ノードがrootなら-1、親がいれば親の番号を入れる
        # size:
        # rank:  
        # self.parent =[-1] * node_size
        self.parent =[-1]*node_size
 
        self.size = [1] * node_size
        self.rank = [1] * node_size
    
    def find_root(self,node):
        # node属する木のrootを探す
        # たどった経路に含まれるnodeの親をrootにつなぎ替える
        if self.parent[node] == -1:             # 自身がrootの場合
            root = node
        else:                                   # 自身がrootでない場合
            root = self.find_root(self.parent[node]) # 再帰的にrootを探す
            self.parent[node] = root            # たどった経路に含まれるnodeの親をrootにつなぎ替える(経路圧縮)
        return root

    def unite(self,node0, node1):
        # node0とnode1が含まれる木を結合する
        
        #node0 node1のrootを求める
        root_node0 = self.find_root(node0) 
        root_node1 = self.find_root(node1)

        if root_node0 != root_node1:
            # rankを比較しrankが小さい方の木を大きい方の木のrootにつなげる
            # rank is sameのときのみrankが増える

            # node1のグループをnode0のグループに結合
            if self.rank[root_node0] == self.rank[root_node1]: # rank is same
                self.parent[root_node1] = root_node0
                self.rank[root_node0] += 1
                self.size[root_node0] += self.size[root_node1]

            # node1のグループをnode0のグループに結合
            elif self.rank[root_node0] > self.rank[root_node1]:
                self.parent[root_node1] = root_node0
                self.size[root_node0] += self.size[root_node1]

            # node0のグループをnode1のグループに結合
            else:
                self.parent[root_node0] = root_node1
                self.size[root_node1] += self.size[root_node0]

    def same(self,node0,node1):
        #同じグループか確かめる
        return self.find_root(node0)==self.find_root(node1)


N,M = map(int,input().split())

bridge_list = []
for _ in range(M):
    bridge_list.append(list(map(int,input().split())))

uft = UnionFindTree(N)
ans_list = [int(N*(N-1)/2)]

for i,bridge in enumerate(bridge_list[::-1]):
    a = bridge[0] -1 
    b = bridge[1] -1 
    if uft.same(a,b): #すでに同じグループの場合不便さの解消なし
        ans_list.append(ans_list[i])
    else:
        a_root = uft.find_root(a)
        b_root = uft.find_root(b)

        a_group_size = uft.size[a_root]
        b_gourp_size = uft.size[b_root]
        
        ans = ans_list[i] - a_group_size*b_gourp_size

        ans_list.append(ans)

        uft.unite(a,b)

ans_list = ans_list[::-1]

for i in range(1,M+1):
    print(ans_list[i])


Measured memory_bytes: 36200