akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N;
    cin >> N;
    string s;
    map<string, long> s_map;
    ll count = 0;
    for(size_t i=0;i<N; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());
        count += s_map[s];
        s_map[s]++;
    }
#ifdef TEST
    for(const auto& _s:s_map)
    {
        cerr << _s.first << ":" << _s.second << endl;
    }
#endif
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 11264
#include<stdio.h>

int main(void) {
  char S[200001];
  char T[200001];
  int i, j;
  int num = 0;
  
  scanf("%s", &S);
  scanf("%s", &T);
  for(i=0; S[i]!='\0'; ++i);
  for(j = 0; j <= i; j++){
    if(S[j] != T[j]){
      num++;
    }
  }  
  printf("%d", num);
  return 0;
}


Measured memory_bytes: 2116
fun main(args: Array<String>) {
    abc140b()
}

fun abc140b() {
    val n = readLine()!!.toInt()
    val eates = readLine()!!.split(" ").map { it.toInt() }
    val scores = readLine()!!.split(" ").map { it.toInt() }
    val bonus = readLine()!!.split(" ").map { it.toInt() }

    var sum = 0
    var beforeEat = -1
    for (i in eates.indices) {
        val eat = eates[i] - 1
        val score = scores[eat] + if (beforeEat != -1 && eat - beforeEat == 1) bonus[eat - 1] else 0
        beforeEat = eat

        sum += score
    }

    println(sum)
}


Measured memory_bytes: 37856
#! env/bin/local python3
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
conditions = []
while True:
    try:
        conditions.append(list(map(int, input().split())))
    except EOFError:
        break

for i in range(0, 10**n):
    if len(str(i)) != n:
        continue
    flag = True
    for c in conditions:
        if str(i)[c[0]-1] != str(c[1]):
            flag = False

    if flag:
        print(i)
        break
else:
    print(-1)






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

int main(){
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	int ans = 1e9; 
	for(int i = 0; i + m - 1 < n; i++){
		int u = i, tmp = 0;
		for(int j = 0; j < m; j++){
			if(s[u] != t[j]){
				tmp++;
			}
			u++;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

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

int main(){
  long long int l,r;
  cin >> l >> r;
  
  long long int n=2019;
  
  for(long long int i=l;i<r&&i<l+2019;i++){
    for(long long int j=i+1;j<=r&&j<l+2020;j++){
      n=min(n,i*j%2019);
      if(n==0){
        i=r;
        break;
      }
    }
  }
  cout << n << endl;
}

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


int main(){
        int N;
        int counter = 0;
        cin >> N;
        vector<int> L(N);
        rep(i,N) cin >> L.at(i);
        sort(L.rbegin(),L.rend());

        for(int i = 0; i < N; i++) {
                for(int j = i + 1; j<N; j++) {

                        int ng = N;
                        int ok = j;
                        while(abs(ok - ng) > 1) {
                                int mid = (ok + ng) / 2;
                                if(L.at(mid) > L.at(i) - L.at(j)) ok = mid;
                                else ng = mid;
                        }
                        counter += ok - j;

                }
        }
        cout << counter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m,a;
string s,t;
int ans[200005];

int main() {
  cin >> n;
  rep(i,n-1) cin >> a, ans[a-1]++;
  rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 4392
n=input()
a=[]
diff_list=[]
for i in range(len(n)-2):
    a.append(n[i:i+3])
for i in a:
    diff=int(i)-753
    if diff < 0:
        diff*=-1
    diff_list.append(diff)
diff_list.sort()
print(diff_list[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    map<int, int> m;
    rep(i, n) {
        cin >> a[i];
        m[a[i]]++;
    }
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    for (auto x : m) {
        pii p = {x.second, x.first}; // 頻度, 整数
        pq.push(p);
    }
    int cnt = 0;
    while (pq.size() > k) {
        cnt += pq.top().first; // 頻度
        pq.pop();
    }
    cout << cnt << endl;
}

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

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int r=0; r <= N/R+1; r++){
        for (int g=0; g <= N/G+1; g++){
            int nokori = N - r * R - g * G;
            if ((nokori >= 0) && (nokori % B == 0)){
                ans++;
            } 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int x,y,i;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y==0)break;
    if(x>y){
      i=x;
      x=y;
      y=i;
      printf("%d %d\n",x,y);
    } else {
      printf("%d %d\n",x,y);
    }
  }
    return 0;
  }

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

int main(){
	string d;
	cin >> d;
	if(d=="SUN") cout << 7;
	if(d=="MON") cout << 6;
	if(d=="TUE") cout << 5;
	if(d=="WED") cout << 4;
	if(d=="THU") cout << 3;
	if(d=="FRI") cout << 2;
	if(d=="SAT") cout << 1;


	return 0;
	
}

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;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<int> H(N);
    REP(i,N)cin >> H[i];
    int maxi = 0,now = H[0],count = 0;
    REP(i,N-1){
        if(H[i+1] <= now){
            count++;
        }else{
            maxi = max(maxi,count);
            count = 0;
        }
        now = H[i+1];
    }
    maxi = max(maxi,count);
    cout <<maxi<< "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
using namespace std;


#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}

const int INF = (1LL << 31) - 1;
const int sqrtN = 512;

struct SqrtDecomposition {
	int N, K;
	vector<ll> data; //内部の値, どのタイミングで変更したか
	vector<ll> bucketSum;
	vector<ll> bucketAdd;
	SqrtDecomposition(int n) : N(n) {
		K = (N + sqrtN - 1) / sqrtN;
		data.assign(K*sqrtN, 0);
		bucketSum.assign(K, 0);
		bucketAdd.assign(K, 0);
	}

	// [s, t)
	void add(ll s, ll t, ll x) {
		for (int k = 0; k < K; ++k) {
			ll l = k * sqrtN, r = (k + 1) *sqrtN;
			if (r <= s || t <= l) continue;
			if (s <= l && r <= t) {
				bucketAdd[k] += x;
			}
			else {
				for (int i = max(s, l); i < min(t, r); ++i) {
					data[i] += x;
					bucketSum[k] += x;
				}
			}
		}
	}

	//[x, y)
	ll getSum(ll s, ll t) {
		ll sum = 0;
		for (int k = 0; k < K; ++k) {
			ll l = k * sqrtN, r = (k + 1)*sqrtN;
			if (r <= s || t <= l) continue;
			if (s <= l && r <= t) {
				sum += bucketSum[k] + bucketAdd[k] * sqrtN;
			}
			else {
				for (int i = max(s, l); i < min(t, r); ++i) {
					sum += data[i] + bucketAdd[k];
				}
			}
		}
		return sum;
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, q; cin >> n >> q;
	SqrtDecomposition sd(n);

	for (int i = 0; i < q; ++i) {
		ll com; cin >> com;
		if (com == 0) {
			ll s, t, x; cin >> s >> t >> x;
			sd.add(s, t+1, x);
		}
		else {
			ll x, y; cin >> x>> y;
			cout << sd.getSum(x, y+1) << endl;
		}
	}
	int a; cin >> a;
	return 0;
}


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

int main()
{
  int x=0,y=0,n;
  string X,Y;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>X>>Y;
    if(X==Y){
      x++;
      y++;
    }
    else if(X>Y)x+=3;
    else y+=3;
  }
  cout<<x<<" "<<y<<endl;
  return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String s = scan.next();
        String t = s.substring(0, n / 2);
        String t1 = s.substring(n / 2);
        System.out.println(t.equals(t1) ? "Yes" : "No");
        scan.close();
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int D[4][2]={ //Right,Up,Left,Down
	{0,1},
	{-1,0},
	{0,-1},
	{1,0},
};

class Maze{
	vector<string> &v;
public:
	int x,y,d;
	Maze(int _x,int _y,int _d,vector<string>&_v)
		: x(_x),y(_y),d(_d),v(_v){
	}
	bool move(){
		int d_orig=(d+3)%4,i=0;
		for(;i<4;i++){
			d=(d_orig+i)%4;
			if(v[y+D[d][0]][x+D[d][1]]=='.')break;
		}
		if(i==4)return false;
		y=y+D[d][0];
		x=x+D[d][1];
		return true;
	}
};

int main(){
	int sx,sy,gx,gy,d;
	int N,M;
	for(;cin>>N>>M&&N&&M;){
		vector<string> m(N+2);
		vector<vector<int> >z(N);
		m[0]=m[N+1]=string(M+2,'#');
		for(int i=1;i<=N;i++){
			string s;
			cin>>s;
			m[i]=string(1,'#')+s+'#';
			z[i-1].resize(M);
			fill(z[i-1].begin(),z[i-1].end(),-1);
		}
		Maze maze(1,1,3,m);
		int r=0;
		do{
			if(maze.y*maze.x>1){
				//m[maze.y][maze.x]='#';
				if(z[maze.y-1][maze.x-1]<0)z[maze.y-1][maze.x-1]=r;
				else if(z[maze.y-1][maze.x-1]!=r)break;
			}

			if(maze.x==1&&maze.y==N)r++;
			if(maze.x==M&&maze.y==N)r++;
			if(maze.x==M&&maze.y==1)r++;
		}while(maze.move()&&(maze.x!=1||maze.y!=1));
		cout<<(r==3&&maze.x==1&&maze.y==1 ? "YES" : "NO")<<endl;
	}
}

Measured memory_bytes: 3156
#include <stdio.h>
int main(void){
	int a = 0, b = 0, c = 0;
	char op;

	while (1){
		scanf("%d %c %d", &a, &op, &b);

		if (op == '+'){
			c = a + b;
		}
		else if (op == '-'){
			c = a - b;
		}
		else if (op == '*'){
			c = a*b;
		}
		else if (op == '/'){
			c = a / b;
		}
		else{
			break;
		}
		printf("%d\n", c);
	}
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define eb emplace_back
#define endl '\n'
#define INF INT_MAX
#define nl cout << endl;
#define sz(a) (a).size()
#define len(a) (a).length()
#define all(v)  v.begin(),v.end()
#define set(v)  memset(v, 0, sizeof(v));
#define some(v, x) v.begin(), v.begin()+x
#define RANGET(i,a) for(ll i=0; i<a; ++i)
#define RANGE(i,a,b) for(ll i=a; i<b; ++i)
#define RANGEI(i,a,b,inc) for(ll i=a; i<b; i+=inc)
#define RANGER(i,a,b) for(ll i=a; i>=b; --i)
#define TEST_CASES(a) int t;if(a==1){t=1;}else{cin>>t;}while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define level 18
#define MAXN 1000001
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<vpl> vvpl;

namespace io {
inline int rdi() { int v; cin >> v; return v; }
inline long long rdll() { long long v; cin >> v; return v;}
inline string rds() { string s; cin >> s; return s; }
inline char rdc() { char c; cin >> c; return c; }
template<class T>
void rdv(T beg_iter, T end_iter) {
    for (; beg_iter != end_iter; ++beg_iter)cin >> *beg_iter;
}
inline void wri(const int v) { cout << v; }
inline void wrll(const long long &v) { cout << v; }
inline void wrs(const string& s) { cout << s; }
inline void wrc(const char c) { cout << c; }
template<class T>
void wrv(T beg_iter, T end_iter, string separator = " ", string end_of_line = "\n") {
    for (; beg_iter != end_iter; ++beg_iter) {
        cout << *beg_iter;
        cout << separator;
    }
    cout << end_of_line;
}
}
using namespace io;

bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {return (a.second < b.second);}

ll binpow(ll a, ll b, ll m) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
string path = "DLRU";
vi di = {1, 0, 0, -1};
vi dj = {0, -1, 1, 0};

void solve();

int main()
{
    fast_io;

    TEST_CASES(1) solve();

    return 0;
}

void solve()
{
    //Adjust t
    int n;
    cin >> n;

    vi A(n);
    rdv(all(A));

    vl dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(A[1] - A[0]);

    RANGE(i, 2, n)
    dp[i] = min(dp[i - 1] + abs(A[i] - A[i - 1]), dp[i - 2] + abs(A[i - 2] - A[i]));

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

Measured memory_bytes: 4492
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  D2(x)       { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  all(x)      (x).begin(), (x).end()
#define  mem(a)      memset(a , 0 ,sizeof a)
#define  deb(x)      cout << #x << " - " << x << "\n";
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcount(x)
#define  deb2(x,y)   cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b)  for(int i=a ; i>=b ; --i)
 
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

void solve(){
    int n; cin >> n;
    vpii v(0);
    vi adj[n+1],vis(n+1),deg(n+1);
    
    int a,b,mx = 0,curr = 0,mxNode,mnNode;
    rep(i,1,n){
        cin >> a >> b;
        ++deg[a], ++deg[b];
        mx = max({mx , deg[a], deg[b]});
        
        adj[a].pb(b), adj[b].pb(a);
        v.pb({a , b});
    }
    
    vi cols(mx),inc(n+1);
    map<pair<int,int>,int>mp;
    
    rep(i,1,mx+1) cols[i-1] = i;
    inc[1] = -1;
    queue<int>q;
    q.push(1);
    
    while(!q.empty()){
        int node = q.front();
        q.pop();
        vis[node] = 1;
        
        for(auto x:adj[node]){
            if(vis[x] == 1) continue;
            mnNode = min(node,x);
            mxNode = max(node,x);
            
            if(inc[node] == cols[curr%mx]){
                curr++;
                curr = curr%mx;
            }
            
            mp[{mnNode , mxNode}] = cols[(curr%mx)];
            vis[x] = 1;
            inc[x] = cols[curr%mx];
            curr++;
            q.push(x);
        }
    }
    
    // D2(inc);
    cout << mx << '\n';
    
    rep(i,0,n-1){
        mnNode = min(v[i].ff , v[i].ss);
        mxNode = max(v[i].ff , v[i].ss);
        cout << mp[{mnNode , mxNode}] << '\n';
    }
}

int main() {
    IOS;
    // int t; cin >> t;
    int t = 1;
    while(t--) solve();
}

Measured memory_bytes: 16700
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toDouble()}.toDoubleArray()
    a.sort()
    var ans : Double = a[0]
    for(i in 1 until n) ans = (ans + a[i]) / 2
    println("%.10f".format(ans))
}

Measured memory_bytes: 37924
def main():
    N, K = map(int, input().split())

    ans = 0
    # i is point
    for i in range(1, N + 1):
        x = 0
        while i * (2 ** x) < K:
            x += 1
        ans += 1 / N * (0.5 ** x)

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

int n, a, b, c;
int l[10];

int mp(int bit, int targ)
{
    int rec = -10;
    rep(i, n) {
	if(bit & (1 << i)) {
	    targ -= l[i];
	    rec += 10;
	}
    }
    
    if(rec >= 0) rec += abs(targ);
    
    return rec;
}

int main()
{
    ci >> n >> a >> b >> c;
    rep(i, n) ci >> l[i];
    
    int m = pow(2, n);
    int ans = 999999;

    rep(i, m) {
	int amp = mp(i, a);
	if(amp == -10) continue;
	
	rep(j, m) {
	    if((i & j) > 0) continue;
	    int bmp = mp(j, b);
	    if(bmp == -10) continue;
	    
	    rep(k, m) {
		if((i & k) > 0 || (j & k) > 0) continue;
		int cmp = mp(k, c);
		if(cmp == -10) continue;
		
		ans = min(ans, amp + bmp + cmp);
	    }
	}
    }
    
    co << ans << en;
    
    return 0;
}




Measured memory_bytes: 256
def max2(x,y):
    return x if x > y else y

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
D = divisors(S)
D.sort()
res = 0
for k in D:
    B = []
    for a in A:
        B.append(a%k)
    B.sort()
    cnt = sum(B)//k
    if k*cnt - sum(B[-cnt:]) <= K:
        res = max2(res, k)

print(res)

Measured memory_bytes: 9244
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
using namespace std;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll a[100];
	a[0]=2;
	a[1]=1;
	for(int i=2;i<100;i++){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int solve(int n)
{
	int cnt = 0;
	while(n % 2 == 0){
		cnt++;
		n /= 2;
	}
	return cnt;
}

int main()
{
	int n;
	cin >> n;
	int ans = 1;
	for(int i = 2; i <= n; i++){
		if(solve(ans) < solve(i)) ans = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	int c1=0,c2=0,c3=0,c4=0;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s=="AC")
		{
			c1++;
		}
		if(s=="WA")
		{
			c2++;
		}
		if(s=="TLE")
		{
			c3++;
		}
		if(s=="RE")
		{
			c4++;
		}
	}
	cout<<"AC x "<<c1<<endl;
	cout<<"WA x "<<c2<<endl;
	cout<<"TLE x "<<c3<<endl;
	cout<<"RE x "<<c4<<endl;
	
	

	
	
	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
 
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=200002;

int dp[N],ans[N];
vi adj[N];

void dfs(int u,int p){
	if(p!=-1){
		ans[u]+=ans[p];
	}
	for(auto i:adj[u]){
		if(i!=p){
			dfs(i,u);
		}
	}
}

void solve(){
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	while(q--){
		int p,x;
		cin>>p>>x;
		p--;
		ans[p]+=x;
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<' ';
	}		
}
 
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}



Measured memory_bytes: 24192
import sys

sys.setrecursionlimit(1000000)


def rec(y, x, f):
    f[y][x] = '0'
    for dy, dx in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0),
            (1, 1)]:
        if 0 <= y+dy < len(f) and 0 <= x+dx < len(f[0]) and f[y+dy][x+dx] == '1':
            rec(y+dy, x+dx, f)


def main():
    while True:
        w, h = [int(i) for i in input().split()]
        if w == 0 and h == 0:
            break
        field = []
        for i in range(h):
            field.append(input().split())
        ans = 0
        for i in range(h):
            for j in range(w):
                if field[i][j] == '1':
                    rec(i, j, field)
                    ans += 1
        print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
const ll INF = 1LL << 61;

int N;
ll X[MAX_N];
ll Y[MAX_N];
char D[MAX_N];

typedef pair<ll, ll> P;
P pos(int i, ll t) {
  switch (D[i]) {
    case 'R': return {X[i] + t, Y[i]};
    case 'L': return {X[i] - t, Y[i]};
    case 'U': return {X[i], Y[i] + t};
    case 'D': return {X[i], Y[i] - t};
  }
  return {0, 0};
}

ll f(ll t) {
  ll x_min = INF;
  ll x_max = -INF;
  ll y_min = INF;
  ll y_max = -INF;
  REP(i, N) {
    P p = pos(i, t);
    chmin(x_min, p.first);
    chmax(x_max, p.first);
    chmin(y_min, p.second);
    chmax(y_max, p.second);
  }
  return (x_max - x_min) * (y_max - y_min);
}

int main2() {
  N = nextInt();
  REP(i, N) {
    X[i] = nextInt() * 2;
    Y[i] = nextInt() * 2;
    cin >> D[i];
  }

  ll lo = 0;
  ll hi = 1e9;
  while (hi - lo >= 3) {
    ll l = (lo * 2 + hi) / 3;
    ll r = (lo + hi * 2) / 3;
    if (f(l) > f(r)) lo = l; else hi = r; // min: > , max: <
  }
  ll minVal = f(lo);
  for (ll i = lo + 1; i <= hi; i++)
    minVal = min(minVal, f(i));
  printf("%.10f\n", minVal / 4.0);
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<=(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,y,a,b;
  int na=-1,nb=-1,nc=-1;
  cin>>n>>y;
  rep(a,n){
    rep(b,n-a){
      int sum=10000*a+5000*b+1000*(n-a-b);
      if(sum==y){
        na=a;
        nb=b;
        nc=n-a-b;
      }
    }
  }
  cout<<na<<" "<<nb<<" "<<nc<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * ZAKIREN第5章 4-6.データ構造の応用
 * 
 * @author tdi5277
 *
 */
public class Main {
	/** 入力用 */
	private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	
	/** 出力用 */
	private static StringBuilder stringBuilder = new StringBuilder();
	
	/**
	 * メイン。
	 * 
	 * @param args 未使用
	 */
	public static void main(String[] args) {

		try {
			// 読み込み
			int n = Integer.parseInt(bufferedReader.readLine());
			
			// 辞書用配列
			Set<String> dictionary = new HashSet<>();
			
			// コマンドを読み込む
			String[] command = new String[2];
			final String SPACE = " ";
			for (int i = 0; i < n; i++) {
				command = bufferedReader.readLine().split(SPACE);
				if(command[0].equals("insert")) {
					// 挿入を実行
					dictionary.add(command[1]);
				} else if (command[0].equals("find")) {
					// 検索を実行
					if (dictionary.contains(command[1])) {
						stringBuilder.append("yes\n");
					} else {
						stringBuilder.append("no\n");
					}
				}
			}
			
			// 読み込み終了
			bufferedReader.close();
			bufferedReader = null;
	
			// 結果出力
			System.out.print(stringBuilder.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}



Measured memory_bytes: 197620
#include <iostream> 
#include <stdio.h>
#define MAX 200005
typedef long long ll; 
using namespace std; 
int main () 
{
    ll N; 
    cin >> N ; 
    int k; 
    cin >> k ; 
    ll arr[MAX]; 
    for(int i=0; i < N; i ++ ) 
    {
        cin >> arr[i]; 
    }
    int answer = N - k;
    //cout << "Printing answer: " << answer << endl; 
    //for(int i=1;i<=answer;i++) 
   // {
        for (int i=0; i < N-k ;  i++ )
        {
            if (arr[k+i]>arr[i])
            {
            cout << "Yes" << endl;
            }   
            else 
            {
            cout << "No" << endl; 
             
            }
        }
    //} 
    
    return 0; 
}


Measured memory_bytes: 5196
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h> 
#include <stack>
#include <bitset>
#include <map>
#include <cmath>
#include <climits>
#include <queue>

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

using namespace std;

int main() {
	int n, cnt = 0;
	string str;
	map<string, int> dic;
	scanf("%d", &n);
	rep(i, n) {
		cin >> str;
		dic[str] = 0;
	}
	for (auto i : dic) cnt++;
	printf("%d", cnt);
}

Measured memory_bytes: 19308
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N; cin>>N;
    int a;
    map<int,int> m;
    REP(i,N) {
        cin>>a;
        REP(j,3) m[a+j-1]++;
    }
    int ans=0;
    for (auto x: m) ans = max(ans,x.second);
    cout<<ans<<endl;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string input_str;

    cin >> input_str;

    for(int i  = 0; i < input_str.size(); i++)
    {
        if(input_str[i] == '?')
        {
          input_str[i] = 'D';
        }
    }

  	cout << input_str << endl;
    return 0;
}


Measured memory_bytes: 3728
N=input()
a=map(int,raw_input().split( ))
mean=sum(a)/len(a)
meanU=mean+1

cost=0
costU=0

for i in a:
    cost+=(mean-i)*(mean-i)
    costU+=(meanU-i)*(meanU-i)

if cost < costU:
    print cost
else:
    print costU


Measured memory_bytes: 2568
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<vector>
#include<bitset>

using namespace std;

const int N=10000,M=1000000007;
stack <int> s;
vector <int> b[N];
bitset <N> bit[N];
int gedian[N],DFN[N],LOW[N],Index,head[N],cnt,n,m,k,root,Cnt,belong[N],E[N],f[209],invf[209];
struct Edge
{
	int nxt,to;
}g[N*2];

void add(int from,int to)
{
	g[++cnt].nxt=head[from];
	g[cnt].to=to;
	head[from]=cnt;
}

int ksm(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=1LL*res*a%M;
		b>>=1,a=1LL*a*a%M;
	}
	return res;
}

void init()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y),add(x,y),add(y,x);
	}
	f[0]=1;
	for (int i=1;i<=200;i++)
		f[i]=1LL*f[i-1]*i%M;
	invf[200]=ksm(f[200],M-2);
	for (int i=199;i>=0;i--)
		invf[i]=1LL*invf[i+1]*(i+1)%M;
}

void Tarjan(int x,int fa)
{
	DFN[x]=LOW[x]=++Index;
	int qwq=1;s.push(x);
	for (int i=head[x];i;i=g[i].nxt)
	{
		int v=g[i].to;
		if(!DFN[v])
		{
			Tarjan(v,x),qwq++;
			LOW[x]=min(LOW[x],LOW[v]);
			if((root==x&&qwq>1)||(x!=root&&DFN[x]<=LOW[v]))
				gedian[x]=1;
			if(DFN[x]<=LOW[v])
			{
				Cnt++;
				int V;
				do
				{
					V=s.top();
					b[Cnt].push_back(V);
					bit[V][Cnt]=1;
					s.pop();
				}while(V!=v);
				b[Cnt].push_back(x),bit[x][Cnt]=1;
			}
		}
		else
			LOW[x]=min(LOW[x],DFN[v]);
	}
}

int C(int a,int b)
{
	return 1LL*f[a]*invf[b]%M*invf[a-b]%M;
}

void work()
{
	for (int i=1;i<=n;i++)
		if(!DFN[i])
			root=i,Tarjan(i,-1);
	/*for (int i=1;i<=Cnt;i++)
	{
		for (int j=0;j<b[i].size();j++)
			printf("%d ",b[i][j]);
		puts("");
	}*/
	int ans1,ans2=1,ans3=1,sum=0;
//	printf("%d\n",Cnt);
	for (int i=1;i<=Cnt;i++)
	{
		for (int j=0;j<b[i].size();j++)
		{
			int k=b[i][j];
			for (int l=head[k];l;l=g[l].nxt)
				if((bit[k]&bit[g[l].to]).test(i))
					E[i]++;
		}
		E[i]>>=1,sum+=E[i];
//		printf("E[i]=%d\n",E[i]);
	}
	ans1=ksm(k,m-sum);
	for (int i=1;i<=Cnt;i++)
	{
		if(E[i]==1)
			ans1=1LL*ans1*k%M;
		else if(E[i]==b[i].size())
		{
			int tmp=0;
			for (int j=1;j<=E[i];j++)
				tmp=(tmp+ksm(k,__gcd(j,E[i])))%M;
			ans2=1LL*ans2*tmp%M*ksm(E[i],M-2)%M;
		}
		else
			ans3=1LL*ans3*C(E[i]+k-1,k-1)%M;
	}
//	printf("%d %d %d\n",ans1,ans2,ans3);
	printf("%d\n",(int)(1LL*ans1*ans2%M*ans3%M));
}

int main()
{
	init();
	work();
	return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
const int N=1e9;
int n;
int minn=N;
int main(){
	cin>>n;
	for (int i=0;++i<n;){
		int k1=n-i,k2=i;
		int a1=0,a2=0;
		for (;k1;k1/=10) a1+=k1%10;
		for (;k2;k2/=10) a2+=k2%10;
		minn=min(minn,a1+a2);
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[100005];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=n-1;i>0;i--)
		if (a[i-1]-a[i]>1)
		{
			cout<<"No";
			return 0;
		}
		else if (a[i-1]-a[i]==1)
			a[i-1]--;
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

const long MOD = 1000000007;
const int N_MAX = 10001;

typedef long long ll;

ll inv[N_MAX];
ll fac[N_MAX];
ll finv[N_MAX];

void init(){
    inv[1] = 1;
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    
    for(int i = 2; i < N_MAX; i++){
        fac[i] = (fac[i-1]*i)%MOD;
        inv[i] = ((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
        finv[i] = (finv[i-1]*inv[i])%MOD;
    }
}

ll comb(ll n, ll m){
    if(n < m) return 0;
    ll ans = (fac[n]*finv[m])%MOD;
    ans = (ans*finv[n-m])%MOD;
    ans += MOD;
    ans %= MOD;
    return ans;
}

int main(){
    int N, K;
    init();
    cin >> N >> K;
    for(int i = 1; i <= K; i++){
        ll tmp = comb(K-1, i-1);
        ll tmp1 = comb(N-K+1, i);
        ll ans = (tmp*tmp1)%MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
struct Node {
	int l, r;
}a[1000005];
bool cmp(Node a, Node b){
	if(a.l < b.l)return 1;
	if(a.l > b.l)return 0;
	return a.r<b.r;
} 
int main(){
	int n,m;
	cin>>n>>m;
	for(int i = 1; i <= m; i++){
		cin>>a[i].l>>a[i].r;
	}
	sort(a + 1, a + m + 1, cmp);
	int ans = 0;
	int l = -9999999, r = -9999999;
	for(int i = 1; i <= m; i++){
		if(a[i].l >= r){
			ans++;
			l = a[i].l;
			r = a[i].r;
		}else {
			l = min(l, a[i].l);
			r = min(r, a[i].r);
		}
	}
	cout<<ans<<endl;
	return 0;
} 
/*
9 7
1 2
1 4
1 5
2 3
2 4
3 7
4 9
*/


Measured memory_bytes: 1024
import sys
N=int(input())
A=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
dp=[0]*N
dp[0]=0
dp[1]=abs(A[0]-A[1])
for i in range(2,N):
    dp[i]=min(abs(A[i]-A[i-2])+dp[i-2],abs(A[i]-A[i-1])+dp[i-1])
print(dp[-1])
    
    


Measured memory_bytes: 20636
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 1e5+5;
ll a[maxn];
int n,m,p,v;
bool check(int x)
{
    if(x<=p) return 1;
    if(a[x]+m<a[p]) return 0;
    ll sum = (ll)m*max(0LL,(ll)v-p);
    for(int i=1;i<=n;i++)
    {
        if(i>=p && i!=x)
        {
            sum-=(ll)min((ll)a[x]+m-a[i],(ll)m);
        }
    }
    return sum<=0;
}
bool cmp(int x,int y) {return x>y;}
signed main()
{
    scanf("%d%d%d%d",&n,&m,&v,&p);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp);
    int l=1,r=n;
    int ans ;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        if(check(mid))
        {
            l=mid+1;
            ans=mid;
        }
        else r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 896
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var NM=Arr.shift();
   if(NM=="0 0")break;
   var nm=NM.split(" ").map(Number);
   var m=nm[1];
   var arr=(Arr.shift()).split(" ").map(Number);
   arr.sort(function(a,b){return b-a;});
   var sum=0;
   for(var i=0;i<arr.length;i++){
      if((i+1)%m!=0)sum+=arr[i];
   }
   console.log(sum);
}

Measured memory_bytes: 10920
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

constexpr int lim = 1e5;
constexpr int mod = 1e9+7;

ll fac[2*(lim+1)], ifac[2*(lim+1)];

ll h, w, a, b;

ll pow(ll x, ll n){
  if(n == 0) return 1;
  
  ll tmp = pow(x * x % mod, n / 2);
  return tmp * ((n % 2)? x: 1) % mod;
}

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

/*
ll comb(ll n, ll r){
  return mul(fac[n], mul(pow(fac[n-r], mod-2), pow(fac[r], mod-2)));
}
*/

ll comb(ll n, ll r){
  return mul(fac[n], mul(ifac[n-r], ifac[r]));
}

int main(){
  cin >> h >> w >> a >> b;

  //階乗テーブル
  fac[0] = 1;
  for(int i=1; i<=2*lim; i++) (fac[i] = fac[i-1] * i) %= mod;

  //逆元テーブル
  ifac[2*lim] = pow(fac[2*lim], mod-2);
  for(int i=2*lim-1; i>=0; i--) (ifac[i] = ifac[i+1] * (i+1)) %= mod;

  ll ans = 0;
  for(int y=1; y<=h-a; y++){
    ans += (comb(b+y-2, y-1) * comb(h-y+w-b-1, h-y) % mod);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		int i=1;

		while(true){
		int a=Integer.parseInt(input.readLine());
		if(a==0){
			break;
		}
		sb.append("Case ").append(Integer.toString(i++)).append(": ").append(Integer.toString(a)).append("\n");


		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 31104
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	char a; cin >> a;
	if (a <= 'Z') cout << 'A';
	else cout << 'a';

	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <numeric>
#include <deque>

using namespace std;

bool check(int goal, int start, deque<int> v) {
	set<int> now, to;
	now.insert(start);
	if(start != 0) {
		v.pop_front();
	}

	for (auto move: v) {
		to.clear();
		for (auto a: now) {
			to.insert(a + move);
			to.insert(a - move);
		}
		now = to;
	}

	return now.count(goal) > 0;
}

int main() {
	string s;
	int x, y;
	cin >> s;
	cin >> x >> y;
	s += 'T';

	deque<int> dx, dy;
	bool is_x = true;
	int len = 0;
	for (auto c : s) {
		if (c == 'T') {
			if (len > 0) {
				if(is_x) {
					dx.emplace_back(len);
				} else {
					dy.emplace_back(len);
				}
			}

			is_x = !is_x;
			len = 0;
		} else if (c == 'F') {
			len++;
		}
	}
	int start_x = s[0] == 'F' ? dx[0] : 0;

	bool ok = check(x, start_x, dx) && check(y, 0, dy);
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


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




Measured memory_bytes: 2124
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    long long q,h,s,d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;
    long long ans=0;
    long long a,b,c;
    a=8*q;
    b=4*h;
    c=2*s;
    ans+=(n/2)*min(a,min(b,min(c,d)));
    if(n%2==1){
        ans+=min(q*4,min(h*2,s));
    }
    cout << ans <<endl;

}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0500?year=2006

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int sumA = 0, sumB = 0;
        for (int i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            if (a > b) {
                sumA += a + b;
            } else if (a < b) {
                sumB += a + b;
            } else {
                sumA += a;
                sumB += b;
            }
        }

        cout << sumA << " " << sumB << endl;
    }
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 
    string s;
    ll q;
    cin >> s >> q;
    deque<char> ds(s.size());
    for (ll i = 0; i < s.size(); i++){
        ds[i] = s[i];
    }
    bool rev = true;
 
    for (ll i = 0; i < q; i++){
        ll t;
        cin >> t;
        if (t == 1){
            rev = !rev;
        }
        else{
            ll f;
            char c;
            cin >> f >> c;
            if (f == 1){
                if (rev){
                    ds.push_front(c);
                }
                else{
                    ds.push_back(c);
                }
            }
            else{
                if (rev){
                    ds.push_back(c);
                }
                else{
                    ds.push_front(c);
                }
            }
        }
    }
 
    if (!rev){
        reverse(ds.begin(), ds.end());
    }
 
    for (ll i = 0; i < ds.size(); i++){
        cout << ds[i];        
    }
    cout << endl;
    
}

Measured memory_bytes: 4064
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
nums = combinations_with_replacement(range(1, m+1), n)
ans = 0

for i in nums:
    tmp = 0
    for j in abcd:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            tmp += j[3]
    ans = max(ans, tmp)
        
print(ans)

Measured memory_bytes: 9184
s = input()


flag = True
for i in range(len(s)):
    if (i+1) %2 == 0:
        if s[i] in ["L","U","D"]:
            continue
        else:
            flag = False
            break
    else:
        if s[i] in ["R","U","D"]:
            continue
        else:
            flag = False
            break

if flag:
    print("Yes")
else:
    print("No")

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

int main() {
  int antena[5];
  for(int i = 0; i < 5; i++){
    cin >> antena[i];
  }

  int k;
  cin >> k;

  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      if(abs(antena[i] - antena[j]) > k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }

  cout << "Yay!" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int n;
    cin>>n;
    int c[n];
    int s[n];
    int f[n];
    for(int i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    for(int i=0;i<n;i++){
        int time;
        if(i==n-1){
            time=0;
        }else{
            for(int k=i;k<n-1;k++){
                if(k==i){
                    time=s[k]+c[k];
                }else{
                    if(time<=s[k]){
                        time=s[k]+c[k];
                    }else{
                        int tmp=time/f[k];
                        if(time%f[k]==0){
                            time=(tmp)*f[k]+c[k];
                        }else{
                            time=(tmp+1)*f[k]+c[k];
                        }
                    }
                }
            }
        }
        cout<<time<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#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; i++)cin >> c.at(i);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long as = lower_bound(a.begin(), a.end(), b.at(i)) - a.begin();
		long long cs = c.end() - upper_bound(c.begin(), c.end(), b.at(i));
		ans += as * cs;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=100005;
long long int n;
long long int a[MAX],b[MAX];
long long int sum,division,sumB;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	division=n*(n+1)/2;
	if(sum%division!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	long long int time=sum/division;
	for(int i=0;i<n;++i){
		int j=(i+1)%n;
		if((a[i]+time-a[j])%n!=0||(a[i]+time-a[j]<0)){
			cout<<"NO"<<endl;
			return 0;
		}
		b[i]=(a[i]+time-a[j])/n;
		sumB+=b[i];
	}
	if(sumB==time){
		for(int i=0;i<n-1;++i) a[n-1]-=b[i]*(n-1-i);
		a[n-1]-=n*b[n-1];
		if(a[n-1]!=0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	else{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
S = input()
charCount = {}
for c in S:
  if c not in charCount:
    charCount[c] = 1
  else:
    charCount[c] += 1

ans = 1
MOD = 1000000007
for c in charCount:
  ans *= (charCount[c]+1)
  ans = ans % MOD
print((ans-1)%MOD)

Measured memory_bytes: 3188
n = int(input())

P = list(map(int, input().split()))

cnt = 0
i = 1
for _ in range(n):
    if n-2 < i:
        break
    cond = 0
    if P[i] < P[i-1]:
        cond += 1
    if P[i] < P[i+1]:
        cond += 1
    if cond == 1:
        cnt += 1
    i += 1

print(cnt)



Measured memory_bytes: 3060
n = int(input())
s = [input() for i in range(n)]
st = [str().join(s_) for s_ in zip(*s)]

cnt = 0

for i in range(n):
    i_ = (n+i)%n
    for k in range(n):
        if s[k] != st[k]:
            break
    else:
        cnt += 1
    s = [s_[-1]+s_[:-1] for s_ in s]
    st = [st[-1]] + st[:-1]

print(cnt*n)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


int main(){
    LL N;
    cin >> N;
    VVI F(N, VI(10));
    REP(i, N) {
        REP(j, 10) {
            cin >> F[i][j];
        }
    }
    VVI P(N, VI(11));
    REP(i, N) {
        REP(j, 11) {
            cin >> P[i][j];
        }
    }

    LL ans = LLONG_MIN;
    FOR(i, 1, 1 << 10) {
        VI c(N);
        REP(j, 10) {
            if (i & ((LL)1 << j)) {
                REP(k, N) {
                    if (F[k][j] == 1) {
                        c[k]++;
                    }
                }
            }
        }
        LL sum = 0;
        REP(j, N) {
            sum += P[j][c[j]];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
                
    return 0;
}


Measured memory_bytes: 256