akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
int main(void)
{
	char s[1001];
	int len;
	scanf("%s",s);
	len=strlen(s);
	if(s[len-1]=='s')	printf("%ses\n",s);
	else printf("%ss\n",s);
	return 0;
}

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

int main(void) {
  long long int a, b, c, k;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
  if (k < a) printf("%lld\n", k);
  else if (k <= (a + b)) printf("%lld\n", a);
  else printf("%lld\n", a - (k - (a + b)));

  return 0;
}


Measured memory_bytes: 1728
#include<iostream>
using namespace std;
int a[5];
int result;

int main(){
	for(int n = 0;n<5;n++){
		cin >> a[n];
		if(a[n] < 40)a[n] = 40;
		result += a[n];
	}
	cout << result/5 << endl;
}

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_`{|}~"); // ok
//string HOGE(".!\"#&%&'()*+,-/:"); // bad
//string HOGE(";<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'"); // bad
//string HOGE("()*+,-/:;<=>?@[\\"); // bad
//string HOGE("]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\"); // bad
//string HOGE("()*+,-/:;<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*,-/:;<=>?@[\\]^_`{|}~"); // ok (no +)

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_"); // ok -5


// included '_'

//string HOGE("_.!\"#&%&'()*+,-/:;<=>?"); // ? more -5

string HOGE("_.!\"#&%&'()*+,-/:"); // ? more -10

int main(void) {
	string s;

	int total = 0;

	while (cin >> s) {
		replace_if(s.begin(), s.end(), [](char c){ return isalpha(c) || c == '.' || HOGE.find(c) != string::npos; }, ' ');
		
		istringstream iss(s);
		int num;
		while (iss >> num) {
			total += num;
		}
	}

	cout << total << endl;

	return 0;}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
	int a[n];
	INPUT(a);
	
	int res = 0;
	FOR(i,n) {
		if (a[i] == i+1) {
			res++;
			i++;
		}
	}
	
	cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;    
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[100008];
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	rep(i, 1, n){cin >> a[i];}
	
	ll mx = 1;
	ll ans = 0;
	rep(i, 1, n){
		if(mx == 1){
			ans += a[i]-1;
			mx = 2;
		}
		else{
			if(mx == a[i]){
				mx++;
			}
			else{
				ans += (a[i]-1)/mx;
			}
		}
	}; 
	
	print(ans)
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	long long a, b, x;
	cin >> a >> b >> x;
	long long ans = b / x - a / x;
	if (a % x == 0) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    double PI = acos(-1);
    double degree = (180.0 / PI), angle = -1.0;
    if (x <= 0.5 * a * a * b) {
        double y = (a * a * b - 2 * x) / (a * b);
        double tanValue = (a - y) / b;
        angle = 90.0 - atan(tanValue) * degree;
    } else {
        double tanTheta = (2.0 * (a * a * b - x)) / (a * a * a);
        double theta = atan(tanTheta) * degree;
        angle = theta;
    }

    cout << fixed << setprecision(9) << angle << endl;
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

const long long mod = 1000000007;
long long fact[200009], inv[200009], factinv[200009];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b & (1LL << i)) != 0) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

void init() {
	fact[0] = 1;
	for (int i = 1; i <= 200000; i++) fact[i] = (1LL * fact[i - 1] * i) % mod;
	for (int i = 0; i <= 200000; i++) inv[i] = modpow(i, mod - 2, mod);
	for (int i = 0; i <= 200000; i++) factinv[i] = modpow(fact[i], mod - 2, mod);
}

long long ncr(long long n, long long r) {
	return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;
}

long long N, A, B, C;

int main() {
	init();
	cin >> N >> A >> B >> C;
	A = A * inv[100 - C]; A %= mod; // A / (A + B)
	B = B * inv[100 - C]; B %= mod; // B / (A + B)
	C = 100LL * inv[100 - C]; C %= mod; // 100 / C

	long long S1 = 1, ret = 0;
	for (int i = 0; i < N; i++) { S1 *= A; S1 %= mod; }
	for (int i = 0; i < N; i++) {
		long long E = ncr(N - 1 + i, i);
		long long prob = E * S1; prob %= mod;
		long long score = 1LL * (N + i) * C; score %= mod;
		ret += prob * score; ret %= mod;
		S1 *= B; S1 %= mod;
	}

	long long S2 = 1;
	for (int i = 0; i < N; i++) { S2 *= B; S2 %= mod; }
	for (int i = 0; i < N; i++) {
		long long E = ncr(N - 1 + i, i);
		long long prob = E * S2; prob %= mod;
		long long score = 1LL * (N + i) * C; score %= mod;
		ret += prob * score; ret %= mod;
		S2 *= A; S2 %= mod;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4992
//void __(){
//	int n,c;
//	cin >> n >> c;
//	_(vi,a,n);
//	_(vi,b,n);
//	vl ans(c+1);
//	ans[0] = 1;
//	rep(i,n){
//		vl tmp(c+1);
//		rep(exi,a[i],b[i]){
//			ll cur = 1;
//			rep(j,c+1){
//				tmp[j] += cur;
//				tmp[j] %= MOD;
//				cur *= exi;
//				cur %= MOD;
//			}
//		}
//
//		vl tmp2(c+1);
//		rep(i,c+1)
//			rep(j,c+1){
//				if(i+j <= c){
//					tmp2[i+j] += tmp[i]*ans[j];
//					tmp2[i+j] %= MOD;
//				}
//			}
//		ans = tmp2;
//	}
//
//	print ans[c];
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define REP_ZERO_INT(i,r) for(int i = 0; i < r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
	int n,c;
	cin >> n >> c;
	_(vi,a,n);
	_(vi,b,n);
	vl ans(c+1);
	ans[0] = 1;
	rep(i,n){
		vl tmp(c+1);
		rep(exi,a[i],b[i]){
			ll cur = 1;
			rep(j,c+1){
				tmp[j] += cur;
				tmp[j] %= MOD;
				cur *= exi;
				cur %= MOD;
			}
		}
		vl tmp2(c+1);
		rep(i,c+1)
			rep(j,c+1){
				if(i+j <= c){
					tmp2[i+j] += tmp[i]*ans[j];
					tmp2[i+j] %= MOD;
				}
			}
		ans = tmp2;
	}
	print ans[c];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    //          int[] split = Console.ReadLine().Split().Select(int.Parse).ToArray();

    public static void Main()
    {
        string S = Console.ReadLine();
        string output = "Good";
        if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
        {
            output = "Bad";
        }
        Console.WriteLine(output);
    }


    

}

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

int main() {
        string A;
        int K;
        cin >> A >> K;

        set<string> s;
        for (int len=1; len<=5; ++len) {
                for (int j=0; j+len-1<A.size(); ++j)
                        s.insert(A.substr(j, len));
        }

        auto it = s.begin();
        advance(it, K-1);
        cout << *it << endl;

        return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  int n; cin >> n;
  string s; cin >> s;

  int ans = 0;
  unordered_set<int> first;
  for(int i = 0; i < n - 1; ++i) {
    first.insert(s[i] - 'a');
    unordered_set<int> latter;
    for(int j = i + 1; j < n; j++) {
      if(first.find(s[j] - 'a') != first.end()) {
        latter.insert(s[j] - 'a');
      }
    }
    ans = max(ans, (int)latter.size());
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
bool isAns = false;
char c = 0;
template<class F>
auto  maximize(int imin,int imax,F &f){
    while(imax - imin > 1){
        int mid = imin + (imax - imin)/2;
        if(f(mid)) imin = mid;
        else imax = mid;
        if(isAns) return 0;
    }
    return imin;
}

signed main(){
    cin >> N; printf("0\n");
    cout.flush();
    string s; cin >> s;
    c = s.front();
    if(c == 'V'){
        return 0;
    } else {
        auto f = [&](int mid){
            printf("%d\n",mid);cout.flush();
            string s; cin >> s;
            char temp = s.front();
            if(temp == 'V'){ isAns = true ;return true;}
            if(mid % 2 == 0 and c == temp) return true;
            if(mid % 2 == 1 and c != temp) return true;
            return false;
        };
        int val = maximize(1,N,f);
        cout << val << endl; cout.flush();
        cin >> s;
    }
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

//幅優先探索(グリッド)
//{i, j}:始点
//visit:1:訪問済み
//task:訪問予定
//depth:始点を0とするtask.front()の深さ
//pushしたマスは訪問済みにすること
ll bfs(ll h, ll w, vector<string> &grid, vector<vector<int>> &dark) {
  vector<vector<ll>> visit(h, vector<ll>(w, 0));
  queue<vector<ll>> task;
  for (int i = 0; i < dark.size(); i++) {
    task.push({dark.at(i).at(0), dark.at(i).at(1)});
    visit.at(dark.at(i).at(0)).at(dark.at(i).at(1)) = 1;
  }
  ll depth = 0;
  while (task.size() > 0) {
    ll sz = task.size();
    for (ll i = 0; i < sz; i++) {
      ll y = task.front().at(0), x = task.front().at(1);
      if (y + 1 < h && grid.at(y + 1).at(x) == '.' && visit.at(y + 1).at(x) == 0) {
        task.push({y + 1, x});
        visit.at(y + 1).at(x) = 1;
      }
      if (y - 1 >= 0 && grid.at(y - 1).at(x) == '.' && visit.at(y - 1).at(x) == 0) {
        task.push({y - 1, x});
        visit.at(y - 1).at(x) = 1;
      }
      if (x + 1 < w && grid.at(y).at(x + 1) == '.' && visit.at(y).at(x + 1) == 0) {
        task.push({y, x + 1});
        visit.at(y).at(x + 1) = 1;
      }
      if (x - 1 >= 0 && grid.at(y).at(x - 1) == '.' && visit.at(y).at(x - 1) == 0) {
        task.push({y, x - 1});
        visit.at(y).at(x - 1) = 1;
      }
      task.pop();
    }
    depth++;
  }
  return depth - 1;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) cin >> grid.at(i);
  vector<vector<int>> dark(0);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (grid.at(i).at(j) == '#') dark.push_back({i, j});
  cout << bfs(h, w, grid, dark) << endl;
}

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

int main(){
  int S;
  cin >> S;
  const int64_t mod=1e9+7;
  vector<int64_t> dp(S+1,0);
  dp.at(0)=1;
  for(int i=3;i<=S;i++){
    dp.at(i)=(dp.at(i-1)+dp.at(i-3))%mod;
  }
  cout << dp.at(S) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	vector<vector<int>> a(N, vector<int>(32)),b(N, vector<int>(32));
	vector<int> T(32);
	for (int i = 0; i < N; i++) {
		ll c; cin >> c;
		for (int j = 0; c; j++) {
			a[i][j] = c % 2;
			c /= 2;
			T[j] = (T[j] + a[i][j]) % 2;
		}
	}
	
	for (int i = 0; i < N; i++) {
		ll ans = 0, two = 1;
		for (int j = 0; j < 32; j++) {
			int bit = (T[j] + a[i][j]) % 2;
			if (bit) ans += two;
			two *= 2;
		}
		cout << ans << " ";
	}
	cout << endl;
}

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

using namespace std;
int n,x,t,ans1,ans2;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>x>>t;
    while(ans2 < n){
        ans2 += x;
        ans1 += t;
    }
    cout<<ans1<<'\n';
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main(){
  int H,W; cin >> H >> W;
  vector<string> field(H);
  rep(i, H) cin >> field[i];
  vector<vector<int>> dp(H + 1,vector<int>(W + 1, 0));
  dp[0][0] = 1; 
  rep(i, H) {
    rep(j, W) {
      //     cout << i << " " << j << endl; 
      if(j + 1 < W) if(field[i][j + 1] == '.') {
	dp[i][j + 1] += dp[i][j];
	dp[i][j + 1] %= MOD;
      }
      if(i + 1 < H) if(field[i + 1][j] == '.') {
	  dp[i + 1][j] += dp[i][j];
	  dp[i + 1][j] %= MOD;
      }
    }
  }
  cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 9396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int a, b, c, d, e, f, N, M;
string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin  >> N>>s;
	int i;
	for (i = 0; i < N; i++)
	{
		if (i >= s.size())
			break;
		cout << s[i];
	}
	if (i < s.size())
		cout << "...";
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  string s;
  cin>>s;
  int r = 0;
  for(int i=0;i<s.length();i++){
    r += ((s[i]-'0')%9);
  }
  if(r%9== 0)cout<<"Yes";
  else cout<<"No";

}


int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  // cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println((c - a + b >= 0) ? (c - a + b) : 0);
	}
}

Measured memory_bytes: 22612
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k; cin>>n>>k;
    int ans=n-k+1,v=0,cnt=1;
    vector<int> p(n,0),l(n-k+1,0);
    rep(i,n) cin>>p[i];
    set<pp> s;
    rep(i,n-1){
        if(p[i]<p[i+1]) cnt++;
        else cnt=1;
        if(cnt>=k){
            l[i-k+2]=1;
            if(v) ans--;
            v=1;
        }
    }
    rep(i,k) s.insert(mk(p[i],i));
    for(int i=1;i<n-k+1;i++){
        if(l[i]==0){
            if((*begin(s)).second==i-1 && (*rbegin(s)).first<p[i+k-1]){
                ans--;
            }
        }
        s.insert(mk(p[i+k-1],i+k-1));
        s.erase(mk(p[i-1],i-1));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13552
s = input()
ans = 1
if s[0] != 'A':
    ans = 0
if not 'C' in s[2:-1]:
    ans = 0
cnt = 0
for i in s:
    if i in [chr(i) for i in range(65, 65+26)]:
        cnt += 1
if cnt != 2:
    ans = 0
if ans == 1:
    print('AC')
else:
    print('WA')


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

struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
	Node *y = NIL;
	Node *x = root;
	Node *z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while (x != NIL){
		y = x;
		if (z->key < x->key){
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if (y == NIL){
		root = z;
	}
	else {
		if (z->key < y->key){
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		string com;
		cin >> com;
		if (com == "insert"){
			int x;
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 24692
#include <iostream>
#include<string>
#include <vector>
const int ABCS = 26;
int main()
{
	std::string s;
	std::vector<int>nums(ABCS);
	while (getline(std::cin, s)) {

		for (auto c : s) {
			if (c <= 'z' && c >= 'a') {
				++nums[c - 'a'];
			}
			if (c <= 'Z' && c >= 'A') {
				++nums[c - 'A'];
			}
		}
	}
	for (int i = 0; i < ABCS; ++i) {
		std::cout << char('a' + i) << " : " << nums[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef vector<vector<ll>> llmap;

int main(int argc, char const *argv[])
{
  ll h, w;
  cin >> h >> w;
  llmap map = llmap(h, vector<ll>(w));
  vector<tuple<ll, ll, ll, ll>> ope(0);
  REP(i, h)
  {
    REP(j, w)
    {
      cin >> map[i][j];
    }
  }
  REP(i, h)
  {
    REP(j, w - 1)
    {
      if (map[i][j] % 2 != 0)
      {
        map[i][j]--;
        map[i][j + 1]++;
        ope.push_back(make_tuple(i, j, i, j+1));
      }
    }
  }
  REP(i, h - 1)
  {
    if (map[i][w - 1] % 2 != 0)
    {
      map[i][w - 1]--;
      map[i + 1][w - 1]++;
      ope.push_back(make_tuple(i, w-1, i+1, w-1));
    }
  }
  cout << ope.size() << endl;
  for (auto o : ope)
  {
    cout << get<0>(o) + 1 << " " << get<1>(o) + 1 << " " << get<2>(o) + 1  << " " << get<3>(o) + 1 << endl;
  }
  return 0;
}


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

int main(){
  int dx[4] = { 1, 0, -1, 0 };
  int dy[4] = { 0, 1, 0, -1 };
  int height, width;
  cin >> height >> width;

  vector<string> field(height);
  for (int h = 0; h < height; ++h) cin >> field[h];

  int sx, sy, gx, gy;
  int ans = 0;
  for (int h = 0; h < height; ++h) {
    for (int w = 0; w < width; ++w) {
      if (field[h][w] == '.') {
        sx = h;
        sy = w;
      }
      else{
        continue;
      }
      vector<vector<int> > dist(height, vector<int>(width, -1)); 
      dist[sx][sy] = 0; // スタートを 0 に
      int dis = 0;

      queue<pair<int, int> > que; 
      que.push(make_pair(sx, sy)); // スタートを push
      while (!que.empty()) {
        pair<int, int> current_pos = que.front(); // キューの先頭を見る (C++ ではこれをしても pop しない)
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop(); // キューから pop を忘れずに

        for (int direction = 0; direction < 4; ++direction) {
          int next_x = x + dx[direction];
          int next_y = y + dy[direction];
          if (next_x < 0 || next_x >= height || next_y < 0 || next_y >= width) continue; // 場外アウトならダメ
          if (field[next_x][next_y] == '#') continue; // 壁はダメ

          // まだ見ていない頂点なら push
          if (dist[next_x][next_y] == -1) {
              que.push(make_pair(next_x, next_y));
              dist[next_x][next_y] = dist[x][y] + 1; // (next_x, next_y) の距離も更新
              dis = max(dis,dist[next_x][next_y]);
          }
        }
      }
      ans = max(ans,dis);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

// using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	ll getRemainNum(const std::vector<ll>&h, int n, ll a, ll b, ll num) {
		ll res = 0;
		ll eachDamage = a - b;
		ll accumDamage = b * num;
		rep(i, n) {
			if (h[i] > accumDamage) {
				res += (h[i] - accumDamage - 1) / eachDamage + 1;
			}
		}
		return res;
	}
}

int main() {

	int n;
	ll a, b;
	std::cin >> n >> a >> b;
	std::vector<ll> h(n);
	rep(i, n) std::cin >> h[i];
	std::sort(allof(h), std::greater<ll>());
	// 1回攻撃するたびに敵全員のHPをBだけ減らす
	// さらに，敵一帯に対してa - bダメージ与える

	// あと追加のa-bダメージが何回必要か
	ll right = (h[0] - 1) / b + 2;
	ll left = -1;
	// 左の境界線を探す
	while (right - left > 1) {
		ll mid = (right + left) / 2;
		ll remain = getRemainNum(h, n, a, b, mid);
		if (remain > mid) {
			// 右を探す
			left = mid;
		}
		else right = mid;
	}
	// mid = low, right = low + 1 = mid + 1 となっている
	ll ans = right;

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1024
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    fastio();

    int h, w, m;
    cin >> h >> w >> m;
   	map<int, int> x, y;
   	set<pair<int, int>> t;
   	for(int i = 0; i < m; ++i){
   		int a, b;
   		cin >> a >> b;
   		x[a] ++;
   		y[b] ++;
   		t.insert({a, b});
   	}
   	int mx = 0;
   	for(auto it : x){
   		mx = max(mx, it.s);
   	}
   	int my = 0;
   	for(auto it : y){
   		my = max(my, it.s);
   	}

   	set<pair<int, int>> px, py;
   	for(auto it : x)
   		if(it.s == mx)
			px.insert({it.f, it.s});

   	for(auto it : y){
   		if(it.s == my)
   			py.insert({it.f, it.s});
   	}

   	int ans = 0;
   	for(auto it1 : px){
   		for(auto it2 : py){
   			ans = max(ans, it1.s + it2.s - (int)t.count({it1.f, it2.f}));
   			if(ans == it1.s + it2.s)
   				break;
   		}
   	}
   	cout << ans;
    return 0;
}

/*

*/

Measured memory_bytes: 73892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> Plp;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,T;
    cin >> N >> T;
    vector<ll> A(N), B(N);
    vector<vector<ll>> dp1(3001, vector<ll>(3001));
    vector<vector<ll>> dp2(3001, vector<ll>(3001));
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    rep(i,N){
        rep(j,T){
            if(j-A[i] >= 0){
                cmax(dp1[i+1][j], dp1[i][j-A[i]] + B[i]);
            }
            cmax(dp1[i+1][j], dp1[i][j]);
        }
    }
    for(ll i=N;i>0;i--){
        rep(j,T){
            if(j-A[i-1] >= 0){
                cmax(dp2[i-1][j], dp2[i][j-A[i-1]] + B[i-1]);
            }
            cmax(dp2[i-1][j], dp2[i][j]);
        }
    }
    ll ans = 0;
    //cout << dp1[0][T-1] << " " << dp1[1][T-1] << " " << dp1[2][T-1] << " " << dp1[3][T-1] << endl;
    //cout << dp2[0][T-1] << " " << dp2[1][T-1] << " " << dp2[2][T-1] << " " << dp2[3][T-1] << endl;
    REP(i,0,N){
        rep(j,T){
            cmax(ans, dp1[i][j] + dp2[i+1][T-1-j] + B[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 144256
#pragma GCC optimize("O2,unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 506;
int mat[maxn][maxn], pres[maxn][maxn], n;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void rem(int x, int y) {
	queue<pair<int, int>> a;
	pres[x][y] = 0;
	a.push({x, y});
	mat[x][y]--;
	while(!a.empty()) {
		int x, y;
		tie(x, y) = a.front();
		a.pop();
		for(int i = 0; i < 4; i++) {
			int tx = x + dx[i], ty = y + dy[i];
			if(tx>=0&&tx<=n&&ty>=0&&ty<=n&&mat[tx][ty]>mat[x][y]+pres[tx][ty]) {
				mat[tx][ty] = mat[x][y]+pres[tx][ty];
				a.push({tx, ty});
			}
		}
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;++n;
	for(int i = 1; i < n; i++)
		for(int j = 1; j < n; j++) {
			mat[i][j] = min({i, n-i, j, n-j});
			pres[i][j] = 1;
		}
	ll ans = 0;
	for(int v, i = 0; i < (n-1)*(n-1); i++) {
		cin >> v;
		ans += mat[1 + (v-1)/(n-1)][1 + (v-1)%(n-1)] - 1;
		rem(1 + (v-1)/(n-1), 1 + (v-1)%(n-1));
		/**
		cout << 1 + (v-1)/(n-1) << " " << 1 + (v-1)%(n-1) << "=======\n";
		for(int i = 0; i <= n; i++, cout << '\n')
			for(int j = 0; j <= n; j++)
				cout << mat[i][j] << " ";
		cout << ans << "=======\n";
		***/
	}
	cout << ans;
}

Measured memory_bytes: 5600
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def is_right(a, b, c):
    a2 = a*a
    b2 = b*b
    c2 = c*c

    return a2==b2+c2 or b2==c2+a2 or c2==a2+b2

def main():
    N = int(input())

    for _ in range(N):
        a, b, c = map(int, input().split())

        result = is_right(a, b, c)
        print("YES" if result else "NO")

if __name__ == "__main__": main()

Measured memory_bytes: 7664
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    //dp[i] denotes the minimum cost to reach ith stone
    // 0 < i < n - 1 are the stones
    //We are asked to dind the cost to reach last stone i.e dp[n - 1]
    //Initially there is infinite cost to reach ith stones
    vector<int> dp(n, INT_MAX);
  
    //To reach first stone there is no cost. SO dp[0] = 0
    dp[0] = 0;
   //To reach second stone the frog can jump from 0th stone costing dp[1] = abs(h[1] - h[0])
    dp[1] = abs(h[1] - h[0]);
    
    //For every other stones 2 <= i < n, the frog can jump from the (i - 1), (i - 2)...(i - k)th stones 
    for(int i = 2; i < n; i++){
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
    //Print minm cost to reach (n - 1)th stone
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 4000
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>

int main(void) {
	int step, rotate;
	double x, y;
	int angle;

	x = y = 0;
	angle = 90;
	scanf("%d,%d", &step, &rotate);
	while (step != 0 || rotate != 0){
		x += step * cos(angle / 180.0 * acos(-1));
		y += step * sin(angle / 180.0 * acos(-1));
		angle = (angle - rotate + 360) % 360;

		scanf("%d,%d", &step, &rotate);
	}

	printf("%d\n%d\n", (int)x, (int)y);

	return (0);
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int A,B,C,D,E,F;
    cin >> A >> B >>C >>D>>E>>F;
    double R = -1;
    int suw = 0;
    int sug = 0;
    
    rep(a,31) rep(b,31){
        int e = E*(A*a+b*B);
        int w = 100*A*a+100*b*B;
        
        rep(c,901){
            rep(d,901){
                int s = C*c+d*D;
                if(s+w == 0) continue;
                if(w+s > F || e < s) break;
            
                double r = 100*(double)s/(double)(w+s);
                if(r > R){
                    R = r;
                    suw = s+w;
                    sug = s;
                }
            }
        }
        
        
    }
    
    cout << suw csp sug << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;

    s[k-1] = tolower(s[k-1]);

    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import stdin
input = stdin.readline
import collections
import math


__author__ = "Hamukichi (Nombiri)"
__copyright__ = "Copyright 2015, Hamukichi (Nombiri)"
__version__ = "0.1.0"
__date__ = "2015-11-29"
__licence__ = "MIT License"

eps = 10E-4

def is_equal(v1, v2):
    d = abs(v1 - v2)
    if d < eps:
        return True
    return False

class Vector2(collections.namedtuple("Vector2", "x y")):
    """Class for representing a two-dimensional vector.
    :param x: The x component of the vector.
    :type x: float
    :param y: The y component of the vector.
    :type y: float
    """

    __slots__ = ()

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector2(self.x - other.x, self.y - other.y)

    def __mul__(self, other):  # cross product
        return self.x * other.y - self.y * other.x

    def __neg__(self):
        return Vector2(-self.x, -self.y)

    def __pos__(self):
        return Vector2(+self.x, +self.y)

    def __abs__(self):  # norm
        return math.sqrt(float(self.x * self.x + self.y * self.y))

    def dotproduct(self, other):
        """Returns the dot product of this vector and the given vector.
        :param other: The second vector.
        """

        return self.x * other.x + self.y * other.y

lines = stdin.readlines()
n = int(lines[0])
q = int(lines[n+1])

v_set = []
for i in range(1, n+1):
    v_set.append(Vector2(*list(map(int, lines[i].split()))))

def is_involed(p):

    counter = 0

    for i in range(n):
        g_i = v_set[i-1]
        g_in = v_set[i]
        if g_i.y <= g_in.y:
            a = g_i - p
            b = g_in - p
        else:
            b = g_i - p
            a = g_in - p

        if  a * b > 0:
            if a.y  <= 0 < b.y :
                counter += 1
        elif a * b == 0:
            if a.dotproduct(b) <= 0:
                return -1

    return counter

for k in range(q):
    p = Vector2(*list(map(int, lines[n+2+k].split())))
    t = is_involed(p)
    if t < 0:
        print(1)
    elif t % 2 == 0:
        print(0)
    else:
        print(2)












Measured memory_bytes: 6476
from operator import itemgetter
N, M = map(int, input().split())
list = []

for k in range(M):
    p, S = map(str, input().split())
    p = int(p)
    if S == 'WA':
        S = 0
    else:
        S = 1
    list.append([k, p, S])

list.sort(key=itemgetter(1))

#0処理忘れない
if M != 0:
    wacount = 0
    correct = 0
    #初期条件
    if list[0][2] == 0:
        w_count = 1
        c_count = 0
        mark = 1
        ans=[0, 0]
    else:
        w_count = 0
        c_count = 1
        mark = 0
        ans = [1, 0]

    for i in range(1, M):
        if list[i][1] == list[i-1][1]:
            if mark == 1:
                if list[i][2] == 0:
                    w_count += 1
                else:
                    ans = [ans[0]+1, ans[1]+w_count]
                    mark *= 0

        else:
            if list[i][2] == 0:
                w_count = 1
                c_count = 0
                mark = 1
            else:
                w_count = 0
                c_count = 1
                mark = 0
                ans = [ans[0]+1, ans[1]]
else:
    ans = [0, 0]
print(ans[0], ans[1])

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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
    int h, w;
    int ans = 0;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    // すべてのマスに対してスタートを置いていく
    rep(si,h)rep(sj,w) {
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        // i,j のマスが埋まっていなかったらxで更新する.
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            // 確定マスをキューに詰める
            q.push(P(i,j));
        };
        // まずは幅0でスタート
        update(si,sj,0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            // 左, 上, 右, 下の順で４方向を探索する
            rep(dir, 4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if (ni<0||ni>=h||nj<0||nj>=w) continue;
                if (s[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        rep(i,h)rep(j,w) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<string>s(n);
	int a=0, b=0, c=0, d=0;
	rep(i, n) {
		cin >> s[i];
		if (s[i][0] == 'B'&&s[i][s[i].size() - 1] == 'A')a++;
		else if (s[i][0] == 'B')b++;
		else if (s[i][s[i].size() - 1] == 'A')c++;
		else d++;
	}
	int ans = 0;
	rep(i, n) {
		rep(j, s[i].size()-1) {
			if (s[i][j] == 'A'&&s[i][j + 1] == 'B')ans++;
		}
	}
	if (a == 0) {
		ans += min(b, c);
	}
	else if (b + c > 0) {
		ans += a + min(b, c);
	}
	else {
		ans += a - 1;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s; cin>>s;
    int Bnum=0;
    ll ans=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='B'){
            Bnum++;
        }else if(s[i]=='W'){
            ans += Bnum;
        }
    }
    cout << ans << endl;
}


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

using i64 = int64_t;

int main(){
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> v;
    for(int i=0;i<n;++i){
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    vector<vector<int>> dp1(n+1, vector<int>(t, 0));
    for(int i=1;i<=n;++i){
        for(int j=1;j<t;++j){
            dp1[i][j] = max({dp1[i-1][j], dp1[i][j-1], dp1[i][j]});
            if(j - v[i-1].first >= 0)
                dp1[i][j] = max({dp1[i][j], dp1[i-1][j-v[i-1].first] + v[i-1].second});
        }
    }
    vector<vector<int>> dp2(n+2, vector<int>(t, 0));
    for(int i=n;i>0;--i){
        for(int j=1;j<t;++j){
            dp2[i][j] = max({dp2[i+1][j], dp2[i][j-1], dp2[i][j]});
            if(j - v[i-1].first >= 0)
                dp2[i][j] = max({dp2[i][j], dp2[i+1][j-v[i-1].first] + v[i-1].second});
        }
    }

    int ans = 0;
    for(int i=1;i<=n;++i){
        for(int j=0;j<t;++j){
            int tmp = dp1[i-1][j] + dp2[i+1][t-1-j] + v[i-1].second;
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
vector<int> G[200010];

void input() {
    cin >> n;
    REP(i,n-1) {
        int from,to;
        cin >> from >> to;
        from--;
        to--;
        G[from].pb(to);
        G[to].pb(from);
    }
}

int d[200010];

void f(int v, int depth) {
    if (d[v] != -1) return;
    d[v] = depth;
    for (int i = 0; i < G[v].size(); i++) {
        f(G[v][i], depth + 1);
    }
}

void solve() {
    REP(i,n) {
        d[i] = -1;
    }
    f(0,0);

    int ma = -1, id = -1;
    for (int i = 0; i < n; i++) {
        if (d[i] > ma) {
            ma = d[i];
            id = i;
        }
    }
    REP(i,n) {
        d[i] = -1;
    }
    f(id,0);

    int k = 0;
    for (int i = 0; i < n; i++) {
        k = max(k,d[i]);
    }

    if (k % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
}

int main(int argc, char *argv[]){
    input();
    solve();
    return 0;
}


Measured memory_bytes: 21376