akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    string s;
    cin>>s;
    cout<<(count(all(s),'7')?"Yes":"No")<<endl;
}

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

using namespace std;

#define frei(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define fred(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define fri(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define frd(i,n) for (int i = (n) - 1; i >= 0; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )

#define uint64 unsigned long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define pr pair

#define BIT(n) (1<<(n))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define sqr(x) ((x) * (x))

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 5005

const int64 inf = 1e18+5;

int main(int argc, char const *argv[])
{
    /* code */
    // now weight is 10^9 and value is 10^3 this is min dimension so use it,
    // find out min weight if value is i
    int n, w;
    cin >> n >> w;
    int item[n+1][2];
    for(int i = 1; i <= n; i++) {
        cin >> item[i][0] >> item[i][1];
    }
    int sum_value = 0;
    for(int i = 1; i <= n; i++) {
        sum_value += item[i][1];
    }
    //memset(dp, 0, sizeof(dp));
    //memset(new_dp, 0, sizeof(new_dp));
    vector<int64> dp(sum_value+1, inf);
    vector<int64> new_dp(sum_value+1, inf);
    dp[0] = 0;
    new_dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= sum_value; j++) {
            if(j >= item[i][1]) {
                new_dp[j] = min(dp[j], dp[j - item[i][1]] + item[i][0]);
            } else {
                new_dp[j] = dp[j];
            }
        }
        dp = new_dp;
    }
    int64 ans = 0;
    /*for(int i = 1; i <= sum_value; i++) {
        cout << dp[i] << " " ;
    }
    cout << endl;*/
    for(int64 i = 1; i <= sum_value; i++) {
        if(dp[i] <= w) {
           // cout << "Hello " << endl;
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>

using namespace std;
int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u)
        a-=1;
    else if(t==u)
        b-=1;
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
S = input()
if 'R' in S:
    if S[0] == S[1] and S[0] == 'R':
        if S[2] == 'R':
            print(3)
        else:
            print(2)
    elif S[1] == S[2] and S[2] == 'R':
        print(2)
    else:
        print(1)
else:
    print(0)

Measured memory_bytes: 9132
def i_can_not_in_words(h, w):
    if mapp[h][w] == '>':
        mapp[h][w] = '*'
        i_can_not_in_words(h, w+1)
    elif mapp[h][w] == '^':
        mapp[h][w] = '*'
        i_can_not_in_words(h-1, w)
    elif mapp[h][w] == '<':
        mapp[h][w] = '*'
        i_can_not_in_words(h, w-1)
    elif mapp[h][w] == 'v':
        mapp[h][w] = '*'
        i_can_not_in_words(h+1, w)
    elif mapp[h][w] == '*':
        print 'LOOP'
        return
    elif mapp[h][w] == '.':
        print w, h
        return

while True:
    H, W = map(int, raw_input().split(' '))
    if H == 0: break
    mapp = []
    for i in range(H):
        lis = [c for c in raw_input()]
        mapp.append(lis)
    else:
        i_can_not_in_words(0, 0)

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

struct UnionFind {
    vector<ll> par,rank,cnt; // par[i]:iの親の番号,rank[r]:rを根とする木の高さ,cnt[r]:rを根とする木の要素数

    UnionFind(ll N){ //全て根として初期化
        for(ll i = 0; i < N; i++) par.push_back(i);
        rank.assign(N,0);
        cnt.assign(N,1);
    }

    ll root(ll x){ // xの根を返す
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x,ll y){ // xの木とyの木を併合
        ll rx = root(x); 
        ll ry = root(y);
        if (rx == ry) return;

        if(rank[rx] < rank[ry]){
            par[rx] = ry;
            cnt[ry] += cnt[rx]; 
        }else{
            par[ry] = rx;
            cnt[rx] += cnt[ry];
            if(rank[x] == rank[y]) rank[rx] ++;
        }
    }

    ll tsize(ll x){ //　xの木の要素数を返す
        ll rx = root(x);
        return cnt[rx];
    }

    bool same(ll x,ll y){ // xとyが同一の木に存在するかを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,k,l;
    cin >> n >> k >> l;
    UnionFind treer(n),treel(n);
    for(int i = 0;i < k;i ++){
        int p,q;
        cin >> p >> q;
        p --,q --;
        treer.unite(p,q);
    }
    for(int i = 0;i < l;i ++){
        int r,s;
        cin >> r >> s;
        r --,s --;
        treel.unite(r,s);
    }
    map<pair<int,int>,int> mp;
    for(int i = 0;i < n;i ++){
        mp[make_pair(treer.root(i),treel.root(i))] ++;
    }
    for(int i = 0;i < n;i ++){
        cout << mp[make_pair(treer.root(i),treel.root(i))] << " ";
    }cout << endl;
    return 0;
}

Measured memory_bytes: 21104
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	private static final boolean local = false;
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter output;
	//char c = line.nextToken().charAt(0);

	private static void openFile() throws IOException {
		if (local) {
			String inp = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/input.txt";
			String out = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/output.txt";
			br = new BufferedReader(new InputStreamReader(new FileInputStream(inp)));
			output = new PrintWriter(new FileOutputStream(out));
		} else {
			br = new BufferedReader(new InputStreamReader(System.in));
			output = new PrintWriter(System.out);
		}
	}

	private static String _next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	private static int nextInt() {
		return Integer.parseInt(_next());
	}

	private static long nextLong() {
		return Long.parseLong(_next());
	}

	private static double nextDouble() {
		return Double.parseDouble(_next());
	}

	private static String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}

	private static final int maxN = (int) 2e5 + 5;
	private static final int maxM = (int) 1e6 + 5;
	private static final int maxC = (int) 'z' - 'a' + 1;
	private static final int inf = (int) 1e9 + 7;

	private static int N;
	private static String s;
	private static int[] pos, dp, trace;
	static {
		pos = new int[maxC];
		dp = new int[maxN];
		trace = new int[maxN];
	}

	private static void init() {
		for (int i = 0; i < maxN; ++i) {
			dp[i] = inf;
		}
	}

	private static void enter() throws IOException {
		s = nextLine();
		N = s.length();
		s = '!' + s;
	}

	private static void solve() throws IOException {
		for (int i = N; i >= 0; --i) {
			boolean fl = false;
			for (int nex = 0; nex <= 'z' - 'a'; ++nex) {
				if (pos[nex] == 0) {
					dp[i] = 1;
					trace[i] = nex;
					fl = true;
					break;
				}
			}

			if (!fl) {
				for (int nex = 0; nex <= 'z' - 'a'; ++nex) {
					if (dp[i] > dp[pos[nex]] + 1) {
						dp[i] = dp[pos[nex]] + 1;
						trace[i] = pos[nex];
					}
				}
			}

			if (i > 0)
				pos[s.charAt(i) - 'a'] = i;
		}
	}

	private static void doTrace() {
		int ind = 0;
		while (dp[ind] >= 1) {
			if (dp[ind] == 1) {
				output.print((char) (trace[ind] + 'a'));
				break;
			}
			else {
				output.print(s.charAt(trace[ind]));
			}
			ind = trace[ind];
		}
	}

	public static void main(String[] args) throws IOException {
		openFile();
		init();
		enter();
		solve();
		doTrace();
		output.close();
	}
}

Measured memory_bytes: 27476
s=input()
t=input()
n=0

for i in range(len(s)):
    a=len(s)-1


    s=s[a]+s[0:a]
  
    if s==t:
        n=1
        break
        
        
if n==1:
    if len(s)==len(t):
        print("Yes")
else:
    print("No")

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

int main() {
	int N, M;
	int i, j;
	/* s:student
	 * c:checkpoint
	 * [0]:x, [1]:y */
	int s[55][2];
	int c[55][2];

	scanf("%d %d", &N, &M);
	for(i = 0; i < N; i++) scanf("%d %d", &s[i][0], &s[i][1]);
	for(i = 0; i < M; i++) scanf("%d %d", &c[i][0], &c[i][1]);

	for(i = 0; i < N; i++) {
		int minc;
		int mind = 211111111;
		for(j = 0; j < M; j++) {
			int d = abs(s[i][0] - c[j][0]) + abs(s[i][1] - c[j][1]);
			if(d < mind) {
				mind = d;
				minc = j;
			}
		}
		printf("%d\n", minc + 1);
	}

	return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
using namespace std;
typedef long long llong;
void whatday(int m, int d) {
	int z;
	if (m == 1)z = d;
	else if (m == 2)z = 31 + d;
	else if (m == 3)z = 60 + d;
	else if (m == 4)z = 91 + d;
	else if (m == 5)z = 121 + d;
	else if (m == 6)z = 152 + d;
	else if (m == 7)z = 182 + d;
	else if (m == 8)z = 213 + d;
	else if (m == 9)z = 244 + d;
	else if (m == 10)z = 274 + d;
	else if (m == 11)z = 305 + d;
	else if (m == 12)z = 335 + d;
	if (z % 7 == 5)cout << "Monday" << endl;
	else if (z % 7 == 6 % 7)cout << "Tuesday" << endl;
	else if (z % 7 == 0 % 7)cout << "Wednesday" << endl;
	else if (z % 7 == 1 % 7)cout << "Thursday" << endl;
	else if (z % 7 == 2 % 7)cout << "Friday" << endl;
	else if (z % 7 == 3 % 7)cout << "Saturday" << endl;
	else if (z % 7 == 4 % 7)cout << "Sunday" << endl;
}
int main() {
	int m, d;
	while (cin >> m >> d&&m&&d) {
		whatday(m, d);
	}
	return 0;
}

Measured memory_bytes: 3044
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
if N < 1000:
    print('ABC')
else:
    print('ABD')

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

string S;
int K;

int main(){
    cin>>S>>K;
    set<string>st;
    vector<string>v;
    for(int pos=0;pos<S.size();pos++){
        for(int n=1;n<=K&&pos+n<=S.size();n++){
            st.insert(S.substr(pos,n));
        }
    }
    for(auto itr=st.begin();itr!=st.end();itr++){
        v.push_back(*itr);
    }
    sort(v.begin(),v.end());
    cout<<v[K-1]<<endl;
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int sqr(int n){
	return n*n;
}
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	int ret = 10000000;
	for(int i=1; i<=100; i++){
		int curr = 0;
		for(int j=0; j<n; j++) curr+=sqr(arr[j]-i);
		ret = min(ret,curr);
	}
	cout<<ret;
}

Measured memory_bytes: 3600
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, r = Is()
if n < 10:
    print(r+100*(10-n))
    exit()
print(r)

Measured memory_bytes: 64620
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> a;
#define BUY (0)
#define SELL (1)
#define DONOTHING (2)
vector <int> tradeList;
long long ans = 0;
void checkResult(){
    long long money = 1000;
    long long stock = 0;
    for(int i = 0; i < tradeList.size(); i++){
        switch (tradeList[i])
        {
        case /* constant-expression */BUY:
            /* code */
            stock += money/a[i];
            money = money%a[i];
            break;
        case /* constant-expression */SELL:
            /* code */
            money += stock*a[i];
            stock = 0;
            break;
        case /* constant-expression */DONOTHING:
            /* code */
            break;
        
        default:
            break;
        }
    }
    ans = max(ans,money);
}
void dfs(int trade){
    tradeList.push_back(trade);
    if(tradeList.size()==n){
        checkResult();
    }else{
        dfs(BUY);
        tradeList.pop_back();
        dfs(SELL);
        tradeList.pop_back();
        dfs(DONOTHING);
        tradeList.pop_back();
    }
}
int main(){
    cin >> n;
    a = vector<int>(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n-1; i++){
        if(a[i]<a[i+1]){
            tradeList.push_back(BUY);
        }else if(a[i]>a[i+1]){
            tradeList.push_back(SELL);
        }else{
            tradeList.push_back(SELL);
        }
    }
    tradeList.push_back(SELL);
    checkResult(); 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define ll long long
#define f first
#define p_b push_back
#define s second
using namespace std;
struct str
{
    int val,pos,lvl;
};
int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector < vector < ll > > v(n+1, vector < ll > (m+1,0));
    vector < pair < ll, ll> > p;
    for( int i = 0; i < n; i++)
    {
        int x,y;
        cin >> x >> y;
        p.push_back({x,y});
    }
    for( int i = 1; i <= n; i++)
    {
        for( int j = 0; j <= m; j++)
        {
            if(j>=p[i-1].first)
            {
                v[i][j] = max(v[i-1][j-p[i-1].f]+p[i-1].second,v[i-1][j]);
            }
            else
            {
                v[i][j] = v[i-1][j];
            }
        }
    }
    cout << v[n][m];
}


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

int arr[(int)1e5 + 10];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n; cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		sum += x;
		arr[x]++;
	}
	int q; cin >> q;
	for (int i = 1; i <= q; ++i) {
		int b, c; cin >> b >> c;
		sum -= arr[b] * 1LL * (b - c);
		arr[c] += arr[b];
		arr[b] = 0;
		cout << sum << "\n";
	}
	
}


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

int main(){
	long long n,ans;
	
	cin >> n;
	for(int i = 1;i<=sqrt(n);i++){
		if(n%i==0) ans = n/i;
	}
	int d = 0;
	while(ans){
		d++;
		ans/=10;
	}
	cout << d << endl;
}

Measured memory_bytes: 256
#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; cin >> n;
  vector<string> vecn(n);
  rep(i,n) cin >> vecn[i];
  int m; cin >> m;
  vector<string> vecm(m);
  rep(i,m) cin>>vecm[i];

  int ans = 0;
  rep(i,n){
    int count = 0;
    rep(k,n){
      if(vecn[i] == vecn[k]) count++;
    }
    rep(k,m){
      if(vecn[i] == vecm[k]) count--;
    }
    ans = max(ans, count);
  }
  if(ans < 0){
    cout << 0 << endl;
    cout << "flag" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 1005
using namespace std;
int n;
inline int id(int i,int j) {
	return i*n + j;
}
vector<int> G[maxn*maxn];
int vis[maxn*maxn];
int dp[maxn*maxn];
bool dfs(int u) {
	dp[u] = 1;
	vis[u] = 1;
	for(int v : G[u]) {
		if(vis[v]==1)
			return false;
		else {
			if(vis[v]==0 && !dfs(v))
				return false;
			dp[u] = max(dp[u],dp[v]+1);
		}
	}
	vis[u] = -1;
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++) {
		for(int j=1,pre=-1;j<n;j++) {
			int u = i , v;
			cin >> v;
			u--;	v--;
			if(u>v)		swap(u,v);
			int now = id(u,v);
			if(pre!=-1)
				G[pre].emplace_back(now);
			pre = now;
		}
	}
	int m = n*(n-1)+(n-2);
	int ans = 0;
	for(int i=0;i<m;i++)
		if(vis[i]==0) {
			if(dfs(i))
				ans = max(ans,dp[i]);
			else {
				ans = -1;
				break;
			}
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 47488
#include <stdio.h>

int main() {
	int k;//倍数
	int a;//飛距離
	int b;//
	int l;
	scanf("%d", &k);
	scanf("%d%d", &a, &b);
	l = b / k;
	if (a <= k * l)printf("OK");
	else printf("NG");
	return 0;
}

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

string s;
int i,n;
int main()
{
    cin >> s;
    n = s.size();
    int ans = 0;
    for (i = 0; i < n / 2; ++i)
        if (s[i] != s[n - i - 1])
            ++ans;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	char str[5];
	int sum = 0;

	
		scanf("%s", str);

		if (str[0] == str[1] || str[1] == str[2] || str[0] == str[2]) {
			if (str[2] == str[3] || str[0] == str[3] || str[1] == str[3]) {
					if (str[0] == str[1] && str[1] == str[2] || str[0] == str[1] && str[1] == str[3] || str[0] == str[2] && str[3] == str[2]) {
						printf("No\n");
					}
					else printf("Yes\n");
			}
			else printf("No\n");
		}
		else printf("No\n");

	

	


	
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0 ; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0 ; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0 ; i < N-1; i++) {
    cin >> C.at(i);
  }
  
  int satis = B.at(A.at(0) - 1);
  for (int i = 1; i < N; i++) {
    satis += B.at(A.at(i) - 1);
    if (A.at(i) == A.at(i-1) + 1) {
      satis += C.at(A.at(i-1)-1);
    }
  }
  cout << satis << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define M 30
void CHECKMATE(int);

  char ban[8][8];
  int gyou[M],retsu[M],U[M],X[M];

int main(){
  int k,i,j,r,c,x,m;
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      ban[i][j]='.';
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    m=7-c;
    ban[r][c]='Q';
    gyou[r]=retsu[c]=1;
    U[r+c]=X[r+m]=1;
  }
  CHECKMATE(0);
  return 0;
}
void CHECKMATE(int y){
  int i,j,m;
  if(y==8){
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
	printf("%c",ban[i][j]);
      }
      printf("\n");
    }
    exit(0);
  }
  if(gyou[y]==1){
    CHECKMATE(y+1);
  }
  for(i=0;i<8;i++){
    m=7-i;
    if(retsu[i]==0&&U[i+y]==0&&X[y+m]==0){
      ban[y][i]='Q';
      retsu[i]=U[y+i]=X[y+m]=1;
      CHECKMATE(y+1);
      ban[y][i]='.';
      retsu[i]=U[y+i]=X[y+m]=0;
    }
  }
}
  



Measured memory_bytes: 2148
#include<cstdio>
#include<vector>
#include<set>
#include<cstring>


using namespace std;
using vc=vector<char>;
using vi=vector<int>;

char a[2*100000+2];


int main(void)
{
	while(scanf("%[a-z]\n", a)==1)
	{
		int n=strlen(a);
		vi p;
		vi f(256);
		vc ans;
		int c=0;

		p.push_back(n);
		for(int i=n-1;i>=0;i--)
		{
			if(f[a[i]]==0) c++;
			f[a[i]]++;
			if(c==26)
			{
				f.assign(256, 0);
				c=0;
				p.push_back(i);
			}
		}

		int s=0;
		for(;!p.empty();p.pop_back())
		{
//printf("s=%d n=%d p.back()=%d\n", s, n, p.back());
			f.assign(256, 0);
			for(int i=s;i<p.back();i++)
			{
				f[a[i]]++;
			}
			for(int i='a';i<='z';i++)
			{
				if(!f[i])
				{
					ans.push_back(i);
					break;
				}
			}
			for(;s<n;s++)
			{
				if(a[s]==ans.back())
				{
					s++;
					break;
				}
			}
		}
		ans.push_back('\0');
		printf("%s\n", &ans[0]);
	}

	return 0;
}


Measured memory_bytes: 512
s = input()
if(s == "SUN"):
    print(7)
elif(s == "MON"):
    print(6)
elif(s == "TUE"):
    print(5)
elif(s == "WED"):
    print(4)
elif(s == "THU"):
    print(3)
elif(s == "FRI"):
    print(2)
elif(s == "SAT"):
    print(1)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  string s;
  string t;
  cin >> s;
  cin >> t;
  ll n = s.size();
  ll m = t.size();
  // cout << n << endl;
  // cout << m << endl;
  vector<ll> ss(n+1);
  vector<ll> tt(m+1);
  rep(i, n) {
    ll diff = (s[i] == 'A') ? 1 : 2;
    ss[i+1] = ss[i] + diff;
  }
  rep(i, m) {
    ll diff = (t[i] == 'A') ? 1 : 2;
    tt[i+1] = tt[i] + diff;
  }
  // printvec(ss);
  // printvec(tt);
  ll q;
  cin >> q;
  rep(iter, q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a; --b; --c; --d;
    ll sn = ss[b+1] - ss[a]; // [a, b+1)
    ll tn = tt[d+1] - tt[c]; // [a, b+1)
    if (abs(sn-tn)%3 == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int x;
    cin >> x;
    vector<int> p(1, 2);
    bool prime = false;
    int i = 3;
    if (x == 2) {
        prime = true;
    }
    while (prime == false) {
        for (auto a : p) {
            if (i % a == 0) {
                break;
            }
            if (a == p.back()) {
                p.push_back(i);
            }
        }
        if (p.back() >= x) {
            prime = true;
        }
        i++;
    }
    cout << p.back() << endl;
    return 0;
}

Measured memory_bytes: 3732
import sys
from datetime import datetime

S = input()
s_date = datetime.strptime(S, '%Y/%m/%d')
last_heisei = datetime.strptime('2019/04/30', '%Y/%m/%d')

if s_date > last_heisei:
    print('TBD')
else:
    print('Heisei')



Measured memory_bytes: 4336
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    vi v;
    int a,b,c; cin>>a>>b>>c; v.push_back(a); v.push_back(b); v.push_back(c);
    sort(all(v));
    if(v[0]+v[1]==v[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int d, mans=-imax, ans;
	vector<int> c, t, ld, at, us;
	vector< vector<int> >s;

	cin>> d;

	c.resize(26);
	rep(i, 26) cin>> c[i];
	s.resize(d);
	rep(i, d){
		s[i].resize(26);
		rep(j, 26) cin>> s[i][j];
	}
	t.resize(d);
	at.resize(d);
	rep(i, d){
		int tmp=1, ma=-1;
		rep(j, 26){
			if(ma<s[i][j]){
				tmp=j;
				ma=s[i][j];
			}
		}
		at[i]=tmp+1;
	}

	rep(i, d){
		//cout<< t[i] <<endl;
	}

	ld.resize(26);
	us.resize(26);

	/*int m;
	vector<int> qd, qq;
	cin>> m;
	qd.resize(m);
	18875
24854
43469
55888
60565
61786
62459
62952
66424
66996
67742
70781
74134
76245
76970
78168
78566
79404
79455
79507
	qq.resize(m);
	rep(i, m) cin>> qd[i] >> qq[i];*/
	
  	std::random_device seed_gen;
  	std::mt19937 engine(seed_gen());

	int ti = clock();
    while (clock() - ti < 185 * CLOCKS_PER_SEC / 100){
	
		rep(i, 26) us[i]=0;

    	rep(i, d){
			int rs=engine();
			rs=abs(rs)%26;
			while(us[rs]>(i+5)/26) rs=(rs+1)%26;
			us[rs]++;
			t[i]=rs;
			//PV(us);
		}
		ans=0;
		rep(i, 26) ld[i]=0;

		rep(i, d){
			ans+=s[i][t[i]];
			ld[t[i]]=i+1;
			rep(j, 26) ans-=(i-ld[j]+1)*c[j];
		}

		if(mans<ans){
			rep(i, d) at[i]=t[i]+1;
			mans=ans;
			//cout<< mans <<endl;
		}
	}

	rep(i, d) cout<< at[i] <<endl;
 
	return 0;
}

Measured memory_bytes: 3616
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
lines = [[] for _ in range(N)]
for i in range(N-1):
    a,b = inpl()
    a-=1; b-=1
    lines[a].append((b,i))
    lines[b].append((a,i))


def dfs(s,b,v):
    if s == v:
        return set()
    else:
        for t,i in lines[s]:
            if t == b:
                continue
            ret = dfs(t,s,v)
            if ret is not None:
                ret.add(i)
                return ret

        return None


M = inp()
mm = [] # i 番目の条件は mm[i] のラインのどこかに +1 をする
for m in range(M):
    u,v = inpl()
    u-=1; v-=1
    mm.append(dfs(u,-1,v))



dp = [0] * (1<<M)
dp[0] = 1

for i in range(N-1):
    # line i を白くした場合
    # dp[:] = dp[:]
    # line i を黒くした場合
    tmp = 0
    for b,m in enumerate(mm):
        if i in m:
            tmp += (1<<b)

    for b in reversed(range(1<<M)):
        dp[b | tmp] += dp[b]



print(dp[-1])


Measured memory_bytes: 50920
#!/usr/bin/env python3
import sys

def solve(A: int, B: int, C: int):
    L = [A,B,C]
    print([l for l in L if L.count(l) == 1][0])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
sys.setrecursionlimit(10 ** 8)


def 関数(n, k, lipi):
    lipi.sort()
    boy = len(lipi)
    boy = min(k, boy)

    somme = 0
    for i in range(boy):
        somme += lipi[i]
    return somme

def çözmek():
    N, K = map(int, input().split())
    #liste_pi = list(map(int, sys.stdin.readline().rsplit().split()))
    liste_pi = list(map(int, input().split()))
    
    res = []
    res.append(関数(N, K, liste_pi))
    print(*res)

if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> a(n), b(m);
    int max_a = -1000, min_b = 1000;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        max_a = max(max_a, a[i]);
    }
    for (int i = 0; i < m; i++){
        cin >> b[i];
        min_b = min(min_b, b[i]);
    }

    for (int z = x+1; z <= y; z++){
        if (z > max_a && z <= min_b){
            cout << "No War\n";
            return;
        }
    }
    cout << "War\n";
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

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

using namespace std;

const int INF = 1 << 30;

int N, K, A[100000];
int exist[100001], sum;

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++) cin >> A[i];
  int ret = INF, tail = 0;


  for(int i = 0; i < N; i++) {
    while(tail < N && sum < K) {
      sum += exist[A[tail]]++ == 0 && A[tail] <= K;
      ++tail;
    }
    if(sum == K) ret = min(ret, tail - i);
    sum -= exist[A[i]]-- == 1 && A[i] <= K;
  }
  printf("%d\n", ret == INF ? 0 : ret);
}



Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int get(string s,string t){
	int ret  =0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i])ret++;
	}
	return ret;
}

int main(){
	
	string S,T;
	cin>>S>>T;
	swap(S,T);
	int ans = Inf;
	
	for(int i=0;i<T.size();i++){
		if(i+S.size()>T.size())break;
		ans = min(ans,get(S,T.substr(i,S.size())));
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> price(n);
  REP(i,n) {
    cin >> price[i];
  }
  while(m>0) {
    SORTR(price);
    int i = 0;
    int max_n = price[0] / 2;
    while(max_n <= price[i]) {
      price[i] /= 2;
      max_n = max(max_n, price[i]);
      --m;
      ++i;
      if(i >= n || m <= 0) break;
    }
  }
  int ans = 0;
  for(auto& itr : price) {
    ans += itr;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
	
    int i=0;
  	for (; i<A; i++){
      if (S[i] == '-'){
        cout << "No" << endl;
        return 0;
      }
    }
    if (S[i] != '-'){
      cout << "No" << endl;
      return 0;
    }
    i++;
    for (; i<A+B+1; i++){
      if (S[i] == '-'){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    T[a].append([b, 1])
    T[b].append([a, 1])


def dfs(n):
    dist = [-1] * N
    dist[n] = 0
    stack = [n]

    while stack:
        u = stack.pop()
        for v, c in T[u]:
            if dist[v] < 0:
                dist[v] = dist[u] + 1
                stack.append(v)
    return dist


Black = dfs(0)
White = dfs(N - 1)

Black_get = 0
for b, w in zip(Black, White):
    if b <= w:
        Black_get += 1

if Black_get > N // 2:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 48004
input_data= input()
dic={}
yes_flag= 0

for moji in input_data:
  try:
    dic[moji] = dic[moji] + 1
  except KeyError:
    dic[moji] = 1


for keys in dic:
  if dic[keys] == 2:
    yes_flag = yes_flag +1

if yes_flag == 2:
  print('Yes')
else:
  print('No')


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

typedef vector<vector<int> > Graph;
typedef pair<int, int> pii;
struct Node{
  int order, min_order;
};
class BrigeFind{
public:
  BrigeFind(Graph _g){
    g = _g;
    node.resize(g.size(), Node{-1, (int)1e9});
  }
  set<pii> find(){
    if(current_order == 0)dfs();
    return brige;
  }
private:
  void dfs(int current  = 0,
           int previous = -1){
    node[current].order   = current_order;
    node[current].min_order = current_order++;
    int to;
    for (int i = 0; i < g[current].size(); i++) {
      to = g[current][i];
      if(node[to].order == -1) dfs(to, current);
      if(previous == to)continue;
      node[current].min_order =
        min(node[current].min_order,
            node[to].min_order);
    }
    if(node[current].min_order == node[current].order and
       previous != -1){
      if(previous < current)
        brige.insert(pii(previous, current));
      else
        brige.insert(pii(current, previous));
    }
  }
  int current_order = 0;
  set<pii> brige;
  Graph g;
  vector<Node> node;
};

int main(int argc, char *argv[]){
  int n, m;
  std::cin >> n >> m;
  Graph g(n, vector<int>());
  for (int i = 0; i < m; i++) {
    int to, from;
    std::cin >> to >> from;
    g[to].push_back(from);
    g[from].push_back(to);
  }
  BrigeFind bf(g);
  set<pii> bridge = bf.find();
  for (auto i: bridge){
    std::cout << i.first << " " << i.second << std::endl;
  }
  return 0;
}

Measured memory_bytes: 5420
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) throws java.io.IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String snake;
		bf.readLine();
		while ((snake = bf.readLine()) != null) {
			String ans = isSnakeA(snake) ? "A" : isSnakeB(snake) ? "B" : "NA";
			System.out.println(ans);
		}
	}

	private static boolean isSnakeA(String snake) {
		String sa = "^>'(=+)#\\1~$";
		Pattern pa = Pattern.compile(sa);
		Matcher ma = pa.matcher(snake);
		return ma.find();
	}

	private static boolean isSnakeB(String snake) {
		String sb = "^>\\^(Q=)+~~$";
		Pattern pb = Pattern.compile(sb);
		Matcher mb = pb.matcher(snake);
		return mb.find();
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int main() {
  int n;
  int i;
  while(cin >> n && n) {
	for(i=0; n!=1; i++)
	  if( n % 2 ) n = n * 3 + 1;
	  else n /= 2;
	cout << i << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
A = list(map(int,input().split()))
dp = [[0 for i in range(2)] for i in range(N+1)]
dp[0][1] = -10**9

#print(dp)

for i in range(N):
    #print(A[i])
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i])
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i])

#print(dp)
print(dp[N][0])

Measured memory_bytes: 27084
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll h,w;
    cin >> h >> w;
    ll a,b;
    cin >> a >> b;

    cout << (h-a)*(w-b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int INF = 1 << 30;

int c[26];
int t[365];
int s[365][26];
int last[26];

int calc_score(int d) {
	int sum = 0;
	fill(last, last + 26, 0);
	for (int i = 0; i < d; i++) {
		sum += s[i][t[i]];
		last[t[i]] = i + 1;
		for (int j = 0; j < 26; j++) {
			sum -= c[j] * (i + 1 - last[j]);
		}
	}
	return sum;
}

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < 26; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < d; i++) {
		cin >> t[i];
		t[i]--;
	}

	int current_score = calc_score(d);

	int m, dd, qq;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> dd >> qq;
		dd--, qq--;
		int old = t[dd];
		t[dd] = qq;
		int new_score = calc_score(d);
		current_score = new_score;
		cout << current_score << endl;
	}
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,ans=0,a=0,b=0;cin>>n;
  map<P,ll> m;
  string s;
  for(ll x=1;x<=n;++x) {
    s=to_string(x);
    a=s[0]-'0';
    b=x%10;
    m[P{a,b}]+=1;
  }
  for(ll i=1;i<10;++i) {
    for(ll j=1;j<10;++j) {
      ans+=m[P{i,j}]*m[P{j,i}];
    } 
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <time.h>
#define int long long
using namespace std;
struct node
{
	int a,b;
}s[100100];
int n,m,ans,cnt,cn;
int cmp(node x,node y)
{
	return x.a<y.a;
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&s[i].a,&s[i].b);
	}
	sort(s+1,s+n+1,cmp);
	while(cnt<m)
	{
		cn++;
		if(cnt+s[cn].b<=m)
		{
			ans+=s[cn].a*s[cn].b;
			cnt+=s[cn].b;
		}else
		{
			ans+=s[cn].a*(m-cnt);
			cnt+=m-cnt;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main() {
    int th, ts, ah, as;
    cin >> th >> ts >> ah >> as;
    while (th != 0 && ah != 0) {
        ah -= ts;
        if (ah <= 0) {
            cout << "Yes";
            break;
        }
        th -= as;
        if (th <= 0) {
            cout << "No";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>


int main()
{
	int n, a, b;

	scanf("%d", &n);
	if (n == 1) {
		printf("Hello World\n");
	}
	else {
		scanf("%d %d", &a, &b);

		printf("%d\n", a + b);
	}

	return 0;
}

Measured memory_bytes: 128
/*#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")*/
//#pragma GCC optimize("fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("Ofast,no-stack-protector")
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long  ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define pb(x) push_back(x)
#define fr(i, n) for(int i = 0; i < n; ++i)
//typedef cc_hash_table<int, int, hash<int>> hst2;
//typedef cc_hash_table<int, hst2, hash<int>> hst;
typedef pii ord_set_t;
#ifdef ABCD
typedef set<ord_set_t> ordered_set;
int __builtin_popcount(int x)
{
	int cnt = 0;
	for (; x > 0; x >>= 1) cnt += x & 1;
	return cnt;
}

#else
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
mt19937 rnd(239);
using namespace __gnu_pbds;
typedef tree<
	ord_set_t,
	null_type,
	less<ord_set_t>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
#endif
const int N = 51;

int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else

#endif
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b));
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int kekka = 1;
        String s=sc.next();
switch (s){
  case "SUN":
    kekka=7;
    break;
  case "MON":
    kekka=6;
    break;
  case "TUE":
    kekka=5;
    break;
  case "WED":
    kekka=4;
    break;
  case "THU":
    kekka=3;
    break;
  case "FRI":
    kekka=2;
    break;
}
		System.out.println(kekka);      	
	}
}

Measured memory_bytes: 23636
def a ( x1, y1, x2, y2, xp, yp )
    (x2-x1)*(yp-y1) - (y2-y1)*(xp-x1) 
end

while gets
    x1, y1, x2, y2, x3, y3, xp, yp = $_.chomp.split.map(&:to_f)
    puts ([[x1,y1], [x2,y2], [x3,y3]].permutation(3).to_a.map {|k, l, m| a(k[0],k[1],l[0],l[1],xp,yp) * a(k[0],k[1],l[0],l[1],m[0],m[1]) > 0}.uniq==[true])?"YES":"NO"
end
    

Measured memory_bytes: 6144
N = int(input())
A = list( map(int, input().split(" ")) )
B = list( map(int, input().split(" ")) )
C = list( map(int, input().split(" ")) )

satis = 0 #満足度
temp_menu = -1 #１つ前に食べた料理を保存する

for menu in A: #menu:食べた食品
    satis += B[menu-1]
    #今回食べたものが、前回食べたmenuの次ならば追加満足度
    if menu == temp_menu+1 :
        satis += C[temp_menu-1]
    
    temp_menu = menu

print(satis)

Measured memory_bytes: 38256