akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
X = int(input())

total = 0
n = 0

for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            total = 500 *a + 100 * b + 50 * c
            if total == X:
                n += 1

print (n)

Measured memory_bytes: 3064
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
string s;

int main(){
	IOS
	cin >> s;
	int n=s.length();
	for(int i=0;i<n-8;++i){
		cout << s[i];
	}
	cout << '\n';
}


Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
ll num[ten5];
ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    double ans=0.0,half,d,d1,d2;
    //float f,g,h;
    string s,s1;
    //char now,pre,c1,c2;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        num[i]=m;
    }
    for(i=0;i<n;i++)
    {
        cin>>m;
        num2[i]=m;
    }
    for(i=0;i<n;i++)
    {
        a=num[i]-num2[i];
        if(a>0) sum2+=a;
        else
        {
            a=abs(a);
            if(a&1==1)
            {
                sum+=(a+1)/2;
                sum2++;
            }
            else sum+=a/2;
        }
    }
    if(sum2>sum) cout<<"No";
    else cout<<"Yes";
    return 0;
}





Measured memory_bytes: 384
using System;

class AOJ
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string first, second, sum = "";

        for (int i = 0; i < n; i++)
        {
            first = Console.ReadLine();
            second = Console.ReadLine();

            sum = Sum(first, second);

            if (first.Length > 80 || second.Length > 80 || sum.Length > 80)
                Console.WriteLine("overflow");
            else
                Console.WriteLine(sum);
        }
    }


    public  static string Sum(string s1, string s2)
    {

        string str = "", zero = "";
        int a = 0, b;

        if (s1.Length > s2.Length)
        {
            for (int i = 0; i < (s1.Length - s2.Length); i++)
                zero += "0";
            s2 = zero + s2;
        }
        else if (s1.Length < s2.Length)
        {
            for (int i = 0; i < (s2.Length - s1.Length); i++)
                zero += "0";
            s1 = zero + s1;
        }

        for (int i = 0; i < s1.Length; i++)
        {
            b = int.Parse(s1.Substring(s1.Length - i - 1, 1)) + int.Parse(s2.Substring(s2.Length - i - 1, 1)) + a;
            a = b / 10;
            b %= 10;
            str = b.ToString() + str;
        }

        if (a > 0) str = a.ToString() + str;

        return str;
    }
}

Measured memory_bytes: 5904
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	char a,b;cin>>a>>b;
	string x,y;
	for(int i = 0; i < (b- '0'); i++) {
		x.pb(a);
	}
	for(int i = 0; i < (a- '0'); i++) {
		y.pb(b);
	}
	vector<string> c;
	c.pb(x);
	c.pb(y);
	sort(ALL(c));
	cout << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    a: [i32;9],
    n: usize,
    b: [i32;n],
  }
  let mut x = [false;9];
  for bk in b {
    for i in 0..9 {
      x[i] |= a[i] == bk;
    }
  }
  // 0 1 2
  // 3 4 5
  // 6 7 8
  let lines = [
    [0,1,2],
    [3,4,5],
    [6,7,8],
    [0,3,6],
    [1,4,7],
    [2,5,8],
    [0,4,8],
    [2,4,6]];
  let bingo = |x: [bool;9]| { 
    for line in &lines {
      if x[line[0]] && x[line[1]] && x[line[2]] {
        return true;
      }
    }
    return false;
  };
  if bingo(x) {
    println!("Yes");
   } else {
    println!("No");
   }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
#include <bits/stdc++.h>
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    map<char, int> m;
    for(char c = 'a'; c <= 'z'; c++){
        m[c] = 50;
    }

    for (int i = 0; i < n; i++){
        for (char c = 'a'; c <= 'z'; c++){
            int num = count(s[i].begin() , s[i].end() , c);
            m[c] = min(m[c] , num);
        }
    }
    string ans;
    for (char c = 'a'; c <= 'z'; c++){
        string t(m[c] , c);
        ans += t;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	


int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
	}

	int a = 0, b = 0;
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0 or i == 0) a += vec[i];
		else b += vec[i];
	}
	cout << a - b;

	
	return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

	ll n,m,k;
	cin >> n >> m >> k;
	vector<unsigned long> a(n+1);
	vector<unsigned long> b(m+1);

	a[0] = 0;
	b[0] = 0;
	int al=n,bl=m;
	rep1(i,n+1){
		unsigned long x;
		cin >> x;
		a[i] = a[i-1] + x;
	}

	rep1(i,m+1){
		unsigned long x;
		cin >> x;
		b[i] = b[i-1]+x;
	}
	if(a[n] + b[m] <= k){cout << n+m << endl;return 0;}
	pair<unsigned long, ll> max = {0,0};

	rep(i,n+1){
		ll keys = k - a[i];
		int x = upper_bound(all(b),keys) - b.begin() - 1;
		if(a[i]+b[x] <= k && max.sc < i + x){
			max = {a[i]+b[x] , i + x};
		}
	}
	cout << max.sc << endl;
	return 0;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main()
{
	while(cin>>n>>a>>b)
	{
		if(a>b)
		{
			puts("0");
			continue;
		}
		if(n==1)
		{
			if(a!=b)
				puts("0");
			else
				puts("1");	
			continue;
		}
		ll mn=a+b+(n-2)*a;
		ll mx=a+b+(n-2)*b;
		cout<<mx-mn+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner s = new Scanner(System.in);

        String line = s.nextLine();

        char[] chars = line.toCharArray();

        Arrays.sort(chars);

        if (chars[0] == chars[1] && chars[0] != chars[2] && chars[2] == chars[3]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21588
X, Y = map(int, input().split())
MD = pow(10, 9) + 7

def choose(n, a):
    x, y = 1, 1
    for i in range(a):
        x = x * (n - i) % MD
        y = y * (i + 1) % MD
    return x * pow(y, MD - 2, MD) % MD

a = (2*Y-X)//3
b = (Y-2*X)//-3
if a < 0 or b < 0 or (X+Y) % 3 != 0:
    print(0)
    exit()
print(choose(a+b, min(a,b)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
string s;
int n;
void dfs(int c, ll num, ll sum) {
    if (c == n) {
        ans += sum + num;
    } else {
        ll y = s[c] - '0';
        dfs(c + 1, 10*num + y,sum);
        if (num != 0){
            dfs (c+1, y, sum + num);
        } 
    }
}

int main () {
    cin >> s;
    n = s.size();
    dfs(0,0,0);

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define X real()
#define Y imag()

using namespace  std;
using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int, int> pairs;
typedef complex<ll> G;
const int N = 1e5+5;
int a[N];
void solve(){


    string s;
    cin >> s;
    cout << s.substr(0, 3);


}
int main() {
    fast;
    solve();


}


Measured memory_bytes: 3616
//Love and Freedom.
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 20021225
#define N 5010 
#define mdn 1000000007
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return f*s;
}
struct edge{int to,lt;}e[N<<1];
int in[N],cnt,sz[N],f[N],g[N][N],tmp[N],n;
void add(int x,int y)
{
	e[++cnt].to=y; e[cnt].lt=in[x]; in[x]=cnt;
	e[++cnt].to=x; e[cnt].lt=in[y]; in[y]=cnt;
}
void init()
{
	f[0]=1;
	for(int i=2;i<=n;i+=2)
		f[i]=1ll*f[i-2]*(i-1)%mdn;
}
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
void dfs(int x,int fr)
{
	sz[x]=1; g[x][1]=1;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to; if(y==fr)	continue; dfs(y,x);
		memcpy(tmp,g[x],sz[x]+1<<2); memset(g[x],0,sz[x]+1<<2);
		for(int sy=0;sy<=sz[y];sy++)	for(int sx=0;sx<=sz[x];sx++)
			upd(g[x][sx+sy],1ll*g[y][sy]*tmp[sx]%mdn);
		sz[x]+=sz[y];
	}
	for(int i=1;i<=sz[x];i++)	upd(g[x][0],mdn-1ll*g[x][i]*f[i]%mdn);
}
int main()
{
	n=read(); for(int i=1;i<n;i++)	add(read(),read());
	init(); dfs(1,1); printf("%d\n",mdn-g[1][0]);
	return 0;
}

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

namespace ConsoleApp85 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var x = new int[N];
            var y = new int[N];

            for (int i = 0; i < N; i++) {
                var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
                x[i] = st[0];
                y[i] = st[1];
            }

            string allCities = "";
            for (int i = 0; i < N; i++) {
                allCities += i.ToString();
            }

            var perms = Perms(allCities);

            decimal ansSum = 0;

            int index = 0;
            int index_next = 0;

            foreach(var element in perms) {
                for (int i = 0; i + 1 < N; i++) {
                    index = int.Parse(element[i].ToString());
                    index_next = int.Parse(element[i + 1].ToString());

                    ansSum += (decimal)Math.Sqrt(
                                                    Math.Pow(x[index_next] - x[index], 2)
                                                                                     +  Math.Pow(y[index_next] - y[index], 2)
                                                                                                                          );
                }
            }
            Console.WriteLine(ansSum / perms.Count());

        }

        static List<string> Perms(string s) {
            if (s.Length == 1) {
                return new List<string>() { s };
            }

            var ret = new List<string>();
            for (int i = 0; i < s.Length; i++) {
                foreach(string t in Perms(s.Remove(i, 1))) {
                    ret.Add(s[i] + t);
                }
            }

            return ret;
        }
    }
}


Measured memory_bytes: 26944
#abc092c

n=int(raw_input())
a=map(int,raw_input().split())
a.append(0)
a.insert(0,0)
s=[]
for i in xrange(n+1):
 s.append(abs(a[i+1]-a[i]))
ss=sum(s)
for i in xrange(1,n+1):
 print ss+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))


Measured memory_bytes: 11108
N, M = map(int, input().split())

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

l_max = 1
r_min = N

for l, r in lr:
    l_max = max(l, l_max)
    r_min = min(r, r_min)

print(max(r_min - l_max + 1, 0))


Measured memory_bytes: 27332
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct Event {
    string date;
    int time;
    string type;
    string id;
}

void main() {
    int N;
    Event[] events;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        events.destroy;
        foreach (i; 0 .. N) {
            int h, m;
            string date;
            string e, id;
            auto x = readln.chomp.split;
            date = x[0];
            sscanf(x[1].ptr, "%d:%d", &h, &m);
            e = x[2];
            id = x[3];
            int time = h * 60 + m;
            events ~= Event(date, time, e, id);
        }
        return true;
    }
    void solve() {
        struct S {
            int time;
            string id;
        }
        S[] Q1, Q2;
        bool G;
        string prev;
        int[string] T;
        foreach (e; events) {
            static if (false) {
                writeln(e);
                writeln("\t", Q1);
                writeln("\t", Q2);
            }
            if (e.date != prev) {
                if (G) {
                    foreach (q; Q1) {
                        T[q.id] += e.time - q.time;
                    }
                }
                G = false;
                Q1.destroy;
                Q2.destroy;
                prev = e.date;
            }
            if (e.id == "000") {
                if (e.type == "I") {
                    foreach (q; Q2) {
                        Q1 ~= S(e.time, q.id);
                    }
                    Q2.destroy;
                    G = true;
                } else {
                    assert(e.type == "O");
                    foreach (q; Q1) {
                        T[q.id] += e.time - q.time;
                        Q2 ~= S(e.time, q.id);
                    }
                    Q1.destroy;
                    G = false;
                }
            } else {
                if (e.type == "I") {
                    (G ? Q1 : Q2) ~= S(e.time, e.id);
                } else {
                    S[] nQ;
                    foreach (q; (G ? Q1 : Q2)) {
                        if (q.id == e.id) {
                            //writeln(e.id, " out");
                            if (G) {
                                T[q.id] += e.time - q.time;
                            }
                        } else {
                            nQ ~= q;
                        }
                    }
                    (G ? Q1 : Q2) = nQ.dup;
                }
            }
        }
        int Ans = 0;
        foreach (k, v; T) {
            Ans = max(Ans, v);
        }
        writeln(Ans);
    }
    while (input) solve;
}

Measured memory_bytes: 3080
#include <cstdio>
#include <cstring>
int disable[10];
bool check(int num) {
	char s[10];
	sprintf(s,"%d",num);
	int len=strlen(s);
	for(int i=0;i<len;++i) {
		if(disable[s[i]-'0']) return false;
	}
	return true;
}
int main() {
	int n,k,in;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i) {
		scanf("%d",&in);
		disable[in]=true;
	}
	while(1) {
		if(check(n)) {
			printf("%d\n",n);
			break;
		}
		++n;
	}
	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  int n; cin >> n;
  vi a(n);
  map<int, vector<int>> mp;
  bool one = false;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    mp[a[i]].push_back(i);
    one |= a[i] == 1;
  }
  if(!one) {
    cout << -1 << endl;
    return 0;
  }

  vll dp(n, -1);
  for(int i=0;i<n;++i) {
    if(a[i] == 1) {
      dp[i] = i;
    } else {
      if(SZ(mp[a[i]-1]) == 0) continue;
      auto it = lower_bound(mp[a[i]-1].begin(), mp[a[i]-1].end(), i);
      if(it == mp[a[i]-1].begin()) continue;
      it--;
      if(dp[*it] == -1) continue;
      dp[i] = dp[*it] + (i - *it - 1);
    }
  }

  ll ans = LINF;
  for(int i=0;i<n;++i) {
    if(dp[i] == -1) continue;
    ans = min(ans, dp[i] + n - 1 - i);
  }
  cout << ans << endl;



}


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

int main()
{
	uint64_t N;
	set<uint64_t> st;

	cin >> N;
	for(int n=0; n<N; n++){
		uint64_t A;
		cin >> A;
		st.insert(A);
	}
	if(st.size() == N){
		cout << "YES";
	} else {
		cout << "NO";
	}

	return 0;
}


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    vector<int> A;
    int a, b, c;
    cin >> a >> b >> c;
    A.push_back(a);
    A.push_back(b);
    A.push_back(c);
    sort(A.begin(), A.end());
    if ((A[1] == A[0] && A[2] != A[0]) || (A[2] == A[1] && A[1] != A[0])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int s, w;
    cin >> s >> w;

    if(s <= w){
        cout << "unsafe" << endl;
    }    
    else{
        cout << "safe" << endl;
    }

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int q;
  cin >> q;
  for (auto i=0; i<q; i++) {
    string M;
    cin >> M;
    int a, b;
    cin >> a >> b;
    if (M == "print") {
      cout << S.substr(a, b-a+1) << endl;
    } else if (M == "reverse") {
      reverse(S.begin()+a, S.begin()+b+1);
    } else {
      string p;
      cin >> p;
      for (auto i=0; i<p.size(); i++) {
	S[a+i] = p[i]; 
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,a,b;
ll ksm(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll C(ll n,ll b){
	ll ret=1;
	for(int i=1;i<=b;i++){
		ret=ret*(n-i+1)%mod*ksm(i,mod-2)%mod;
	}
	return ret;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>a>>b;
	ll ans=ksm(2,n)-C(n,a)-C(n,b)-1;
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 256
n=input()
if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
  print('hon')
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9048
#include<stdio.h>

int main(){
   int A,B,C,Z;
   scanf("%d %d %d",&A,&B,&C);
   Z = A;
   A = B;
   B = Z;
   Z = A;
   A = C;
   C = Z;
   printf("%d %d %d\n",A,B,C);
}


Measured memory_bytes: 1664
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label

    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top

    def print_top(self): print(self.top)
    def print_right(self): print(self.right)

    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEESSSWWWNNNWWWSSWWSESWS':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

Measured memory_bytes: 7776
#include<stdio.h>
int main(void){
   char s[10], o[10];
   int S[10], C[10];
   C[1] = 1; C[2] = 0; C[3] = 0;
   while ( scanf("%4s", s) != EOF ) {
      /*printf("%c\n", s[0], s[2]);*/
      if ( s[0] == 'A' ) {S[0] = 1;/*printf("keya\n");*/}
      else if ( s[0] == 'B' ) S[0] = 2;
      else if ( s[0] == 'C' ) S[0] = 3;
      if ( s[2] == 'A' ) S[1] = 1;
      else if ( s[2] == 'B' ) {S[1] = 2;/*printf("keya\n");*/}
      else if ( s[2] == 'C' ) {S[1] = 3;/*printf("keyb;\n");*/}
      if ( C [S[0]] == 1 ) { C[S[0]] = 0; C[S[1]] = 1; }
      else if ( C[S[1]] == 1 ) { C[S[0]] = 1; C[S[1]] = 0; }
      /*printf("key\n");
      printf("S[0]:%d S[1]:%d\n", S[0], S[1]);*/
      /*printf("A:%d B:%d C:%d\n", C[1], C[2], C[3]);
      if ( C[1] == 1 ) printf("A\n");
      else if ( C[2] == 1 ) printf("B\n");
      else if ( C[3] == 1 ) printf("C\n");*/
      /*printf("end\n");*/
   }
   if ( C[1] == 1 ) printf("A\n");
   else if ( C[2] == 1 ) printf("B\n");
   else if ( C[3] == 1 ) printf("C\n");
   return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    
    queue<long long> q;

    long long k;
    cin>>k;

    for(int i=1;i<=9;i++) {
        q.push(i);
    }
        
    long long x;
    long long a;
    while(!q.empty()) {
        x=q.front();
        q.pop();
        k--;

        if(k==0) {
            break;
        }

        a=x%10;

        for(int i=-1;i<2;i++) {
            if(a+i>=0&&a+i<10) {
                //cout<<(x*10)+a+i<<endl;
                q.push((x*10)+a+i);
            }
        }
    }
    cout<<x<<endl;


}




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

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

    int ans = n;
    for(; ; ans++){
        string num = to_string(ans);
        bool isok = true;
        for(int i = 0; i < num.length(); i++){
            bool isok1 = true;
            for(int j = 0; j < d.size(); j++){
                if(num[i] == d[j]+'0'){
                    isok1 = false;
                }
            }
            if(!isok1){
                isok = false;
            }
        }
        if(isok) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s,t,u;
  cin >> n >> s >> t;
  for(int i=0;i<=n;i++){
    u=s.substr(0,i)+t;
    if(u.substr(0,n)==s){
      break;
    }
  }
  cout << u.size() << endl;
}

Measured memory_bytes: 256
arr = []
count = 0
n = gets
arr = gets.chomp.split.map(&:to_i)

arr.length.times do |i|
  mini = i
  j = i
  while j < arr.length
    if(arr[j] < arr[mini])
      mini = j
    end
    j += 1
  end
  if(i != mini)
    temp = arr[i]
    arr[i] = arr[mini]
    arr[mini] = temp
    count += 1
  end
end
puts arr.join(' ')
puts count


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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int> > K(M);
    vector<int> P(M);
    rep(i,M){
        int k; cin >> k;
        rep(j,k){
            int s; cin >> s;
            K[i].push_back(s);
        }
    }
    rep(i, M){
        int p; cin >> p;
        P[i] = p;
    }
    int ans = 0;
    rep(i, 1<<N){
        bool check = true;
        rep(j,M){
            int counter = 0;
            rep(k, K[j].size()){
                if (i>>(K[j][k]-1)&1){
                    counter++;
                }
            }
            counter %= 2;
            if (counter == P[j]){
                continue;
            } else {
                check = false;
                break;
            }
        }
        if(check){
            ans++;
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

using namespace std;
int main(){
    int n; std::cin >> n;
    int a[n];int k=0;
    rep(i,n){std::cin >> a[i];k=k^a[i];}
    if(k==0)std::cout << "Yes" << std::endl;
    else cout<<"No"<<endl;
    
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,A) for(int i = 0;i < A;i++)

int main() {
  int A,B;
  cin >> A >> B;
  int x;
  int sum = 0;
  rep(i,B){
    cin >> x;
    sum += x;
  }
  if(A <= sum){
    cout << "Yes" << endl;
  }
else{
cout << "No" << endl;
}
 
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans=0;
  int i=0;
    while(1){
      // cout << ans << endl;
      if(c==0){
	cout << 0 << endl;
	break;
      }
      ans+=a;
      if(c>=ans-a && c<= ans ){
	cout << c+i*60<< endl;
	break;
      }
      ans+=b;
         
      if(ans>=60){
	ans-=60;
	i++;
      }
	if(i+1==60){
	  cout << -1 << endl;
	  break;
	}
    }
    return 0;
}



Measured memory_bytes: 3088
#include <vector>
#include <iostream>
#include <algorithm>

int get_dist(int a, int b) {
	if (a >= b)
		return a - b;
	else
		return b - a;
}

template<typename T>
T gcd(T a, T b) {
	if (a < 0)
		a = -a;
	if (b < 0)
		b = -b;
	while (b != 0) {
		a %= b;
		if (a == 0)
			return b;
		b %= a;
	}
	return a;
}

int main(void) {
	int N, X, x;
	std::cin >> N >> X;

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		std::cin >> x;
		int dist = get_dist(X, x);
		if (i == 0)
			ans = 0;
		ans = gcd(ans, dist);
	}

	std::cout << ans;

	return 0;
}

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

int partition(int A[], char B[], int C[], int p, int r){
	int x = A[r - 1];
	int i = p - 1;

	for(int j = p; j < r - 1; j ++){
		if(A[j] <= x){
			i ++;
			swap(A[i], A[j]);
			swap(B[i], B[j]);
			swap(C[i], C[j]);
		}
	}
	swap(A[++ i], A[r - 1]);
	swap(B[i], B[r - 1]);
	swap(C[i], C[r - 1]);
	return i;
}

void quicSort(int A[], char B[], int C[], int p, int r){
	if(p + 1 < r){
		int q = partition(A, B, C, p, r);
		quicSort(A, B, C, p, q);
		quicSort(A, B, C, q + 1, r);
	}
}

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	int a[N];
	char b[N];
	int c[N];
	for(int i = 0; i < N; i ++){
		cin >> b[i] >> a[i];
		c[i] = i;
	}

	quicSort(a, b, c, 0, N);

	bool flag = true;
	for(int i = 0; i < N - 1; i ++){
		if(a[i] == a[i + 1] && c[i] > c[i + 1]){
			flag = false;
			break;
		}else{
			continue;
		}
	}

	cout << (flag ? "Stable":"Not stable") << endl;

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



Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) {
        cin >> x.at(i);
    }
    int shuukai = (*max_element(x.begin(), x.end())+*min_element(x.begin(), x.end()))/2;
    int longest = 0;
    rep(i,n) {
        int time = abs(shuukai-x.at(i));
        if (time > longest) {
            longest = time;
        }
    }
    cout << longest << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    int V[3];
    cin >> N >> V[0] >> V[1] >> V[2];
    vector<int> I;
    for (int n = 0; n < N; ++n) {
        string s;
        cin >> s;
        int i;
        if (s == "AB") {
            i = 0;
        } else if (s == "BC") {
            i = 1;
        } else {
            i = 2;
        }
        I.push_back(i);
    }
    
    vector<char> Res(N);
    bool b = true;
    for (int n = 0; n < N; ++n) {
        int i = I[n];
        int iNext = (i+1)%3;
        if (V[i] > V[iNext]) {
            --V[i]; ++V[iNext];
            Res[n] = 'A' + iNext;
        } else if (V[i] < V[iNext]) {
            ++V[i]; --V[iNext];
            Res[n] = 'A' + i;
        } else {
            if (V[i] == 0) {
                b = false;
                break;
            }
            if (n == N-1 || I[n+1] == I[n]) {
                ++V[i]; --V[iNext];
                Res[n] = 'A' + i;
            } else if (I[n+1] == iNext) {
                --V[i]; ++V[iNext];
                Res[n] = 'A' + iNext;
            } else {
                ++V[i]; --V[iNext];
                Res[n] = 'A' + i;
            }
        }
    }
    
    if (b) {
        cout << "Yes" << endl;
        for (int n = 0; n < N; ++n) {
            cout << Res[n] << '\n';
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define ll long long
using namespace std;
const int N=1003,P=1e9+7;
int C[N][N],f[N][N];
int add(int x,int y){ x+=y; return x>=P?x-P:x; }
int main(){
    int n,k; cin>>n>>k;
    rep(i,0,n){ C[i][0]=1; rep(j,1,i) C[i][j]=add(C[i-1][j],C[i-1][j-1]); }
    f[0][0]=1;
    rep(c,1,k){
        int a; cin>>a;
        rep(i,0,n)
            rep(j,0,min(i,a))
                f[c][i]=add(f[c][i],(ll)f[c-1][i-j]*C[n-(i-j)][j]%P*C[n-j][a-j]%P);
    }
    cout<<f[k][n]<<endl;
    return 0;
}
/*
4
1
*/


Measured memory_bytes: 6144
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for y in range(n-m+1):
    for z in range(n-m+1):
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count +=1
            if count == m:
                print("Yes")
                exit()
        count=0
print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	string s;
	cin >> s;
	int n=s.size();
	
	vector<int> xc;
	vector<char> a;
	int count =0;
	REP(i,n){
		if(s[i]=='x'){
			count++;
			continue;
		}
		xc.push_back(count);
		count=0;
		a.push_back(s[i]);
	}
	xc.push_back(count);
	
	REP(i,(int)a.size()/2){
		if(a[i]!=a[(int)a.size()-1-i]){
			cout << "-1\n";
			return 0;
		}
	}
	int ans=0;
	REP(i,(int)xc.size()/2){
		ans += abs(xc[i]-xc[(int)xc.size()-1-i]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  string b;
  cin>>a>>b;
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
    cout<<"YES"<<'\n';
  }
  else{
    cout<<"NO"<<'\n';
  }
  return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
int main(){
    long long int n;
    long long int ans = 0;
    scanf("%lld", &n);
    for(int i = 1; i <= n; i ++){
        if(i % 3 != 0 && i % 5 != 0)
            ans = ans + i;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3824
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tate = sc.nextInt();
        
        int yoko = sc.nextInt();
        System.out.print(tate*yoko+" ");//面積
        System.out.println((tate+yoko)*2);//周の長さ
    }
}


Measured memory_bytes: 26164
#include <iostream>

using namespace std;

int main(void){
	int n;
	while(cin >> n){
		if(n == 0) break;
		int ap=0,bp=0;
		for(int i=0;i<n;i++){
			int a,b;
			cin >> a >> b;
			if(a > b){
				ap += a + b;
			}else if(a == b){
				ap += a;
				bp += b;
			}else{
				bp += a + b;
			}
		}
		cout << ap << " " << bp << "\n";
	}
}

Measured memory_bytes: 0
#include <iostream>

int main(){
  int a, b;
  std::cin >> a >> b;

  int ret = 0;
  for(int i = 0; i < 2; i++){
    if(a > b){
      ret += a;
      a--;
    }
    else {
      ret += b;
      b--;
    }
  }

  std::cout << ret << std::endl;

  return 0;
}


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

vector<int> val[4];	
int N, W, w_1, v, w_i;

int findAns(int weight, long long int totWeight, int totVal){
	if(weight==4)
		return totVal;
	int ret = findAns(weight+1, totWeight, totVal);
	int i=0;
	while(i < val[weight].size() && totWeight + w_1 + weight <= W){
		totWeight += w_1 + weight;
		totVal += val[weight][i];
		ret = max(ret, findAns(weight+1, totWeight, totVal));
		++i;
	}
	return ret;
}

int main(){
	scanf("%d %d", &N, &W);
	for(int i=0; i<N; ++i){
		scanf("%d %d", &w_i, &v);
		if(i==0)
			w_1 = w_i;
		val[w_i - w_1].push_back(v);
	}
	for(int i=0; i<4; ++i){
		sort(val[i].begin(), val[i].end(), greater<int>());
	}
	printf("%d\n", findAns(0,0,0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, h;
    cin >> x >> y >> h;
    int a = min(x, y), b = max(x, y), c = b - a;
    cout << a * h + c * h / 2;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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



 
 
int main(){
    int H, W, cnt(0); std::cin >>  H >> W;
    int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
    int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    std::vector<std::string> S(H);
    for(int i(0); i < H; ++i) std::cin >> S[i];
    for(int i(0); i < H; ++i){
        for(int j(0); j < W; ++j){
            if(S[i][j] == '#') continue;
            cnt = 0;
            for(int k(0); k < 8; ++k){
                int ni(i + dx[k]), nj(j + dy[k]);
                if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
                if(S[ni][nj] == '#') ++cnt;
            }
            S[i][j] = cnt + '0';
        }
    }
    for(int i(0); i < H; ++i) std::cout << S[i] << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[0].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    string s;cin>>s;
    int ans;
    if(s=="SAT")ans=1;
    if(s=="SUN")ans=7;
    if(s=="MON")ans=6;
    if(s=="TUE")ans=5;
    if(s=="WED")ans=4;
    if(s=="THU")ans=3;
    if(s=="FRI")ans=2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
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 main(void){
  ll k;
  cin >> k;
  ll ans = 0;
  REP(a, k) REP(b, k) REP(c, k){
    ans += gcd(a+1, gcd(b+1, c+1));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
drct={"N":(0,1),"S":(0,-1),"W":(-1,0),"E":(1,0)}
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    init=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    nowX=nowY=10
    for i in range(M):
        d,l=raw_input().split()
        for j in range(int(l)):
            nowX+=drct[d][0]
            nowY+=drct[d][1]
            L[nowY][nowX]=0
    print "Yes" if L==init else "No"

Measured memory_bytes: 4276
#include <iostream>
#include <vector>

using namespace std;

void dfs(vector<vector<int> > &G, int s, vector<int> &dist, int c) {
    dist[s] = c;
    for (auto u: G[s]) {
        if (dist[u] != -1)
            continue;

        dist[u] = c + 1;
        dfs(G, u, dist, c+1);
    }
}

int main() {
    int n;  cin >> n;
    vector<vector<int> > G(n);
    for (int i = 0; i < n-1; i++) {
        int a, b;   cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    vector<int> dist1(n, -1), distn(n, -1);
    dfs(G, 0, dist1, 0);
    dfs(G, n-1, distn, 0);

    int cnt1 = 0, cntn = 0;
    for (int i = 0; i < n; i++) {
        if (dist1[i] <= distn[i])
            cnt1++;
        else 
            cntn++;
    }

    if (cnt1 > cntn)
        cout << "Fennec" << endl;
    else 
        cout << "Snuke" << endl;
    return 0;
}

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

int main(){
    int N;
    int W;
    cin >> N >> W;
    vector<int>weight(110);
    vector<int>value(110);
    for(int i=0; i<N;i++){
        cin >> weight.at(i) >> value.at(i);
    }
    vector<vector<long long int>>dp(110,vector<long long int>(100100,0));
    
    //ちょうどWのときの最大の価値を計算
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j-weight.at(i)>=0){
            dp.at(i+1).at(j) = max(dp.at(i).at(j-weight.at(i))+value.at(i),dp.at(i+1).at(j));
            }
            dp.at(i+1).at(j) = max(dp.at(i+1).at(j),dp.at(i).at(j));
            
        }
    }
    cout << dp.at(N).at(W) << endl;
}

Measured memory_bytes: 90380
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> PI;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=2e6+5;
int tree[maxn][26],cnt,e[maxn],n,f[maxn],up[maxn];
char s[maxn];

void insert(char *s)
{
    int p=0;
    for(int i=0;s[i];i++)
    {
        int k=s[i]-'a';
        if(!tree[p][k])
        {
            tree[p][k]=++cnt;
            f[cnt]=p;
            up[cnt]=k;
        }
        p=tree[p][k];
    }
    e[p]++;
}

int main()
{
    n=read();
    REP(i,1,n)
    {
        scanf("%s",s);
        int len=strlen(s);
        for(int i=0,j=len-1;i<j;i++,j--)
            swap(s[i],s[j]);
        insert(s);
    }
    f[0]=-1;
    LL ans=0;
    for(int i=cnt;i>=1;i--) if(e[i])
    {
        if(e[i]>1) ans+=1ll*e[i]*(e[i]-1)/2;
        set<char> v;
        v.insert(up[i]);
        int x=f[i];
        while(x!=-1)
        {
            for(int j=0;j<26;j++)
                if(tree[x][j]!=i && e[tree[x][j]] && v.count(j))
                    ans+=1ll*e[i]*e[tree[x][j]];
            v.insert(up[x]);
            x=f[x];
        }
    }
    cout<<ans;

    return 0;
}


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

int memo[55];
int fib(int n)
{
    if ( memo[n] == -1 ) {
        if ( n <= 1 ) memo[n] = 1;
        else memo[n] = fib(n - 1) + fib(n - 2);
    }
    return ( memo[n] );
}

int main()
{
    int n;
    fill_n(memo, 55, -1);
    cout << fib((cin >> n, n)) << endl;
    return ( 0 );
}


Measured memory_bytes: 3096
import sys
# input = sys.stdin.readline

n = int(input())
S = [input() for i in range(n)]

A = [[], [], []]

u = 0

for i in range(n):
    a = 0
    b = 0
    for j in range(len(S[i])):
        if S[i][j] == "(":
            a += 1
        else:
            a -= 1
            b = min(b, a)
    u += a
    if a > 0:
        A[0].append([b, a])
    elif a == 0:
        A[1].append([b, a])
    else:
        A[2].append([a-b, a])



if u != 0:
    print("No")
    sys.exit()

# print(A)

A[0].sort(reverse=True)
A[2].sort()

# print(A)


ng = 0
a = 0
for i in range(len(A[0])):
    a += A[0][i][0]
    if a < 0:
        ng = 1
        break
    a += A[0][i][1]-A[0][i][0]
    if a < 0:
        ng = 1
        break

if ng == 0:
    for i in range(len(A[1])):
        a += A[1][i][0]
        if a < 0:
            ng = 1
            break
        a -= A[1][i][0]

if ng == 0:
    a = 0
    for i in range(len(A[2])):
        aa = A[2][i][1]
        bb = aa-A[2][i][0]
        a -= A[2][i][0]
        if a < 0:
            ng = 1
            break
        a += -bb
        if a < 0:
            ng = 1
            break

# print(a)

if ng == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 237556