akhauriyash/Code-Regression huggingface dataset:
import sys, math
input = sys.stdin.readline

def print_tuple(t):
    print('{} {}'.format(t[0], t[1]))

def describe(depth, p1, p2):
    if(depth == 0):
        return 
    s = (((2 * p1[0] + 1 * p2[0]) / 3), ((2 * p1[1] + 1 * p2[1]) / 3))
    t = (((1 * p1[0] + 2 * p2[0]) / 3), ((1 * p1[1] + 2 * p2[1]) / 3))
    u_x = (t[0] - s[0]) * math.cos(math.radians(60)) - (t[1] - s[1]) * math.sin(math.radians(60)) + s[0]
    u_y = (t[0] - s[0]) * math.sin(math.radians(60)) + (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]
    u = (u_x, u_y)

    describe(depth - 1, p1, s)
    print_tuple(s)
    describe(depth - 1, s, u)
    print_tuple(u)
    describe(depth - 1, u, t)
    print_tuple(t)
    describe(depth - 1, t, p2)

N = int(input())
start = (0.0, 0.0)
end = (100., 0.)
print_tuple(start)
describe(N, start, end)
print_tuple(end)





Measured memory_bytes: 5744
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, T] = [int(input_raw[0]), int(input_raw[1])]
    min_cost = sys.maxint
    for i in range(N):
        input_raw = read_func().strip().split()
        [c, t] = [int(input_raw[0]), int(input_raw[1])]
        if t <= T:
            min_cost = min(min_cost, c)
    if min_cost < sys.maxint:
        print min_cost
    else:
        print "TLE"

if __name__ == '__main__':
    main()

Measured memory_bytes: 2932
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Measured memory_bytes: 165848
#include <iostream>
using namespace std;
int main()
{
	
	char letter;
	cin >> letter;

	letter = tolower(letter);
	if (letter == 'z')
	{
		cout << "This the last letter :\n";
	}
	else{ cout << char(int(letter) + 1); }
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

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

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5; // CAMBIAR ESTE

// GJNM
int a[maxN];

int main() {
	int n;
	ri(n);
	FOR(i, 0, n) {
		ri(a[i]);
	}
	int ans = 0;
	FOR(i, 0, n) {
		FOR(j, i + 1, n) {
			FOR(k, j + 1, n) {
				if ( a[i] == a[j] || a[j] == a[k] || a[i] == a[k] )
					continue;
				if ( (a[i] + a[j] > a[k]) && (a[i] + a[k] > a[j]) && (a[k] + a[j] > a[i]))
					ans++;
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}

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

using namespace std;

template <typename T>
class WeightedUnionFind {
 private:
  std::vector<int> parent;
  std::vector<T> weight;

 public:
  WeightedUnionFind(int n) : parent(n, -1), weight(n, 0) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    int rx = root(parent[x]);
    weight[x] += weight[parent[x]];
    return parent[x] = rx;
  }

  bool is_same(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  T distance(int x, int y) {
    root(x), root(y);
    return weight[y] - weight[x];
  }

  bool unite(int x, int y, int w) {
    int rx = root(x), ry = root(y);
    w += weight[x] - weight[y];
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry), w *= -1;
    weight[ry] = w;
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  WeightedUnionFind<int64_t> uf(N);
  vector<int> L(M), R(M), D(M);
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> D[i];
    L[i]--, R[i]--;
    if (uf.is_same(L[i], R[i])) {
      if (uf.distance(L[i], R[i]) != D[i]) {
        cout << "No" << '\n';
        return 0;
      }
    } else {
      uf.unite(L[i], R[i], D[i]);
    }
  }
  cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 6612
a, b = map(int, input().split())
s = input()
if len(s) != a + b + 1:
    print('No')
    exit()
else:
    for i in range(len(s)):
        if i == a:
            if s[i] != '-':
                print('No')
                exit()
        else:
            if not s[i].isdecimal():
                print('No')
                exit()
    print('Yes')


Measured memory_bytes: 3060
/*** author: yuji9511 ***/
#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(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 print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    ll v = c - (a-b);
    if(v > 0){
        print(v);
    }else{
        print(0);
    }
    
}


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


int main()
{

    //freopen("Input.txt","r",stdin);
    // ios_base :: sync_with_stdio(false);
   ll s,w;
   cin>>s>>w;
   if(s<=w)
    cout<<"unsafe"<<endl;
   else
    cout<<"safe"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define INF (int) 2e9
#define MOD (int) 1e9 + 7

#define MAX_N 100

int memo[MAX_N][MAX_N];
int row[MAX_N], col[MAX_N];

int f(int l, int r, int pos){
    if(pos != -1){
        if(pos == r){
            return INF;
        }
        return min(f(l, pos, -1) + f(pos + 1, r, -1) + row[l] * col[pos] * col[r], f(l, r, pos + 1));
    }
    if(memo[l][r]>0) return memo[l][r];
    if(r-l==0){
        return 0;
    }
    return memo[l][r] = f(l, r, l);
}

int main(){
    int n;
    cin >> n;
    
    rep(i, n){
        cin >> row[i] >> col[i];
    }
    cout << f(0, n-1, -1) << endl;
    return 0;
}


Measured memory_bytes: 3420
n,m = map(int, input().split())
H_list = list(map(int, input().split()))
line = [1 for i in range(n)]
for i in range(m):
  a,b = map(int, input().split())
  if H_list[a-1] < H_list[b-1]:
    line[a-1] = 0
  elif H_list[a-1] > H_list[b-1]:
    line[b-1] = 0
  else:
    line[a-1] = 0
    line[b-1] = 0
print(sum(line))

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n >> m >> x;
    vl cost(n + 10);
    REP(i, n + 1) {
        cost[i] = 0;
    }

    MREP() {
        cin >> a;
        cost[a] = 1;
    }

    ll sum_n = 0;
    ll sum_0 = 0;
    for (int i = x; i <= n; ++i) {
        sum_n += cost[i];
    }

    for (int i = x; i >= 0; --i) {
        sum_0 += cost[i];
    }

    MSG(min(sum_n, sum_0))
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int a;
    string s;
    cin>>a>>s;
    (a>=3200) ? (cout<<s<<endl) : (cout<<"red"<<endl);
}


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

#define int long long
const int mod = 1e9+7;

signed main(){
	int n;
	cin>>n;
	vector<int>pref(n+1),suf(n+1);
	pref[0]=0;
	suf[0]=n*(n+1)/2;
	for(int i=1;i<=n;i++){
		pref[i]=pref[i-1]+i;
		suf[i]=suf[i-1]-(i-1);
	}
	int k;
	cin>>k;
	--k;
	int sum=0;
	for(int i=k;i<=n;i++)sum=(sum+suf[n-i]-pref[i]+1)%mod;
	cout<<sum<<endl;
}


Measured memory_bytes: 6364
#include<stdio.h>
int main()
{
    int a ,b,c,k;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b&&b==c&&c==a){
            k=1;
        printf("%d\n",k);}
    else if(a==b&&b!=c&&a!=c)
    {
        k=2;
        printf("%d\n",k);
    }
     else if(b==c&&a!=b&&a!=c)
    {
        k=2;
        printf("%d\n",k);
    }
      else if(c==a&&c!=b&&a!=b)
    {
        k=2;
        printf("%d\n",k);
    }
 else if(a!=b&&b!=c&&c!=a)
    {
        k=3;
        printf("%d\n",k);
    }



}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    bool ok = 1;
    char tmp = s[0];
    FOR(i,1,4){if(tmp==s[i])ok=0; tmp=s[i];}
    if(ok){out("Good");}else{out("Bad");}

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N;
string r;
int main()
{
  cin >> N;

  r = N == 0 ? "0" : "";
  while (N != 0)
  {
    r += to_string(abs(N % 2));
    N -= abs(N % 2);
    N /= -2;
  }
  reverse(ALL(r));

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int int500 = sc.nextInt();
		int int100 = sc.nextInt();
		int int50 = sc.nextInt();
		int total = sc.nextInt();
		int count= 0;
		for(int a = 0 ; a <= int500 ;a++) {
			for(int b = 0 ; b <= int100;b++) {
				for(int c = 0; c <= int50;c++) {
					int sum = a*500 + b*100 + c*50;
					if(sum == total)count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35612
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int se[n+1],sw[n+1],e=0,w=0,i;
	
	for(i=0;i<n;i++)
	{
		if(s[i]=='E')
		{
			e++;
			se[i+1]=e;
			sw[i+1]=w;
		}
		else
		{
			w++;
			sw[i+1]=w;
			se[i+1]=e;
		}
	}
	int sum=0,minv=300005;
	for(i=1;i<=n;i++)
	{
		if(i==1) sum= se[n]-se[1];
		else if(i==n) sum = sw[n-1];
		else sum = sw[i-1] + se[n] - se[i];
		
		minv=min(sum,minv);
	}
	
	cout<<minv;
	
	return 0;
} 

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

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

std::string N;
int main() {
    std::cin >> N;
    if(N[0]==N[1] && N[1] == N[2]) {
        std::cout << "Yes" << std::endl;
    } else if(N[1] == N[2] && N[2] == N[3]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))
MAX_INT = 10**9 + 7

def choose(n, k):
  x, y = 1, 1
  for i in range(k):
    x = x * (n-i) % MAX_INT
    y = y * (k-i) % MAX_INT

  return ( x * pow(y, MAX_INT-2, MAX_INT) ) % MAX_INT

print( (pow(2, N, MAX_INT) - 1 - choose(N, A) - choose(N, B)) % MAX_INT)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

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

    ll n;
    cin >> n;
    const ll mod = 1e9 + 7;
    vector<ll> dp(n + 4);
    dp[3] = 1;
    REP(i, 3, n + 1)
    {
        dp[i] = (dp[i] + dp[i - 1]) % mod;
        if (i + 3 <= n)
            dp[i + 3] = (dp[i + 3] + dp[i]) % mod;
    }

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool> vecbool;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<vecint> vec2int;
typedef vector<vecbool> vec2bool;
int dx[4]{-1, +1, 0, 0};
int dy[4]{0, 0, -1, +1};
vecll a;
vecll sum;
vector<vector<ll>> memo;
int n;
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
ll dfs(int l, int r) {
  if (memo[l][r] != -1) return memo[l][r];
  ll res = LLONG_MAX;
  for (int i = l; i < r; i++) {
    res = min(res, dfs(l, i) + dfs(i + 1, r));
  }
  res += sum[r + 1] - sum[l];
  memo[l][r] = res;
  return res;
}
int main() {
  init();
  cin >> n;
  a.resize(n);
  for (auto& e : a) cin >> e;
  memo = vector<vector<ll>>(n, vecll(n, -1));
  sum = vecll(n + 1, 0);
  REP(i, n) sum[i + 1] = sum[i] + a[i];
  REP(i, n) memo[i][i] = 0;
  REP(i, n - 1) memo[i][i + 1] = a[i] + a[i + 1];
  cout << dfs(0, n - 1) << endl;
}


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

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
const int ps=33;
int n,X[1010],Y[1010];
int pw[ps];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int trs[4]={'D','U','L','R'};
int Ans[1010][40];
inline void swic(int i,int ts,int es)
{
	if(ts>=es) return;
	int sx;
	if(Ans[i][ts]=='R') sx='L',Ans[i][es]='R';
	if(Ans[i][ts]=='L') sx='R',Ans[i][es]='L';
	if(Ans[i][ts]=='U') sx='D',Ans[i][es]='U';
	if(Ans[i][ts]=='D') sx='U',Ans[i][es]='D';
	for(int j=ts;j<es;j++) Ans[i][j]=sx;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		X[i]=read(), Y[i]=read();
	int op=(X[1]+Y[1])&1;
	for(int i=1;i<=n;i++)
		if(op^((X[i]+Y[i])&1))
		{
			puts("-1");
			exit(0);
		}	
	printf("%lld\n",ps-op);
	pw[0]=1; pw[1]=1;
	for(int i=2;i<ps;i++) pw[i]=pw[i-1]*2;
	for(int i=op;i<ps;i++)
		printf("%lld ",pw[i]); puts("");
	if(!op) for(int i=1;i<=n;i++)
		X[i]++,Ans[i][0]='L';
	for(int i=ps-1;i>=1;i--)
	{
		for(int j=1;j<=n;j++)
		{
			int sx=X[j],sy=Y[j];
			for(int k=0;k<4;k++)
			{
				int vx=sx+dir[k][0]*pw[i],
					vy=sy+dir[k][1]*pw[i];
				if(abs(vx)+abs(vy)<=pw[i])
				{
					X[j]=vx; Y[j]=vy;
					Ans[j][i]=trs[k];
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<ps;j++)
		{
			int tj=j+1;
			while(!Ans[i][tj]&&tj<ps) tj++;
			swic(i,j,tj-1);
			j=tj-1;
		}
		for(int j=op;j<ps;j++)
			putchar(Ans[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int k=sc.nextInt();
        P p[] = new P[n];
        for (int i = 0; i < p.length; i++) {
			p[i] = new P(sc.nextInt()-1, sc.nextInt());
		}
        sort(p);
        long s=0,v=0;
        int c=n-k+1,z=n-k;
        int u[]=new int[n];
        for (int i = 0; i < k; i++) {
			s+=p[n-i-1].d;
			if(0==u[p[n-i-1].id]) v++;
			u[p[n-i-1].id]++;
		}
        long ans=s+v*v;
        s+=v*v;

        while(--c>=0) {
        	if(u[p[c].id]!=0)continue;
        	v++;
        	while(z<n && u[p[z].id]==1)z++;
        	if(z==n)break;
        	u[p[z].id]--;
        	u[p[c].id]++;
        	s += -p[z].d + p[c].d + 2*v-1;
        	z++;
        	ans = max(ans,s);
        }
	     
        out.println(ans);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

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

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int()] * N
    x = [[] for i in range(N)]
    y = [[] for i in range(N)]
    for i in range(N):
        A[i] = int(input())
        for j in range(A[i]):
            xij, yij = map(int, input().split())
            x[i].append(xij - 1)
            y[i].append(yij)
    ans = 0
    for b in range(1 << N):
        flg = True
        for i in range(N):
            if not b & 1 << i:
                continue
            for j in range(A[i]):
                if 1 & b >> x[i][j] ^ y[i][j]:
                    flg = False
                    break
            if not flg:
                break
        if flg:
            ans = max(ans, bin(b)[2:].count("1"))
    print(ans)
    return


main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int n; 
	cin >> n;
	int visited[n] = { };
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans = 0;
	int tmp = 0;
	while(tmp != 1 && visited[tmp] != 1){
		ans++;
		visited[tmp] = 1;
		tmp = a[tmp] - 1;
	}
	if(tmp == 1) cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 19:16:59 2018
ABC104C
@author: maezawa
"""
import math

d, g = list(map(int, input().split()))
p = []
c = []
for i in range(d):
    pi, ci = list(map(int, input().split()))
    p.append(pi)
    c.append(ci)
 
min_cnt = 10**11 
    
for i in range(2**d):
    istr = '0'*d + format(i,'b')
    used = []
    cnt = 0
    maney = 0   
    for j in range(d):
        if istr[-1-j] == '1':
            maney += c[j]+p[j]*(j+1)*100
            cnt += p[j]
            used.append(j)
    if maney >= g:
        if min_cnt > cnt:
            min_cnt = cnt
            #print(istr)
            continue
    else:
        k = d-1
        while k>=0:
            if k not in used:
                break 
            k -= 1
        rem = math.ceil((g-maney)/(100*(k+1)))
        if rem >= p[k]:
            continue
        else:
            cntp = cnt + rem
            if min_cnt > cntp:
                min_cnt = cntp
                #print(istr, rem)
                continue
    #print(min_cnt, istr)
print(min_cnt)
                        
        
            

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

///dijkstra
///////////
static const ll MAX = 100001;
static const ll INFTY = (ll)1 << 55;
static const int WHITE = 1;
static const int GRAY = 2;
static const int BLACK = 3;
vector<pair<int, int>>adj[MAX];
ll d[MAX];
priority_queue<pair<int, int>>PQ;
int color[MAX];
ll n;
void dijkstra(ll x) {
	repe(i, 1, n) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[x] = 0;
	PQ.push(make_pair(x, x));
	color[x] = GRAY;
	while (!PQ.empty()) {
		pair<ll, ll> f = PQ.top(); PQ.pop();
		ll u = f.second;
		color[u] = BLACK;

		if (d[u] < f.first * (-1))continue;

		rep(j, 0, adj[u].size()) {
			ll v = adj[u][j].first;
			if (color[v] == BLACK)continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}
}

int main()
{
	//int k, u, v, c;
	//cin >> n;
	//rep(i, 0, n) {
	//	cin >> u >> k;
	//	rep(j, 0, k) {
	//		cin >> v >> c;
	//		adj[u].push_back(make_pair(v, c));
	//	}
	//}

	//dijkstra(2);
	cin >> n;
	rep(i, 0, n - 1) {
		ll a, b, c; cin >> a >> b >> c;
		adj[a].push_back(make_pair(b, c));
		adj[b].push_back(make_pair(a, c));
	}

	ll q, k; cin >> q >> k;
	dijkstra(k);
	rep(i, 0, q) {
		ll x, y; cin >> x >> y;
		cout << d[x] + d[y] << endl;
	}

	return 0;
}

Measured memory_bytes: 9716
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
/*ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
void solve()
{
    ll n;
    cin>>n;
    string s1;
    set<string> s;
    for(ll i=0;i<n;i++)
    {
        cin>>s1;
        s.insert(s1);
    }
    cout<<s.size()<<endl;
}

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


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

int main(){
 int n;
  cin>>n;double d;cin>>d;
  int ans = 0;
  double x,y;
  for(int i=0;i<n;i++){
  	cin>>x>>y;
    double k = (x)*(x) + (y)*(y);
    if(k<=d*d) ans++;
  }
  cout<<ans;
  
}

Measured memory_bytes: 3816
from collections import deque
n,m = tuple(map(int,input().split()))

edge = []

for i in range(m):
  edge.append(tuple(map(lambda a:int(a)-1,input().split())))
  
matrix = [[0]*n for _ in range(n)]
  
for a,b in edge:
  matrix[a][b] = 1
  matrix[b][a] = 1
  
ans = 0

for a,b in edge:
  matrix[a][b] = 0
  matrix[b][a] = 0
  
  checked = [False]*n
  queue = deque([0])
  while(len(queue)>0):
    q = queue.popleft()
    if checked[q]:
      continue
    else:
      checked[q] = True
      mat = matrix[q]
      for i in range(n):
        if mat[i] == 1:
          queue.append(i)
  if not all(checked):
    ans+=1
  
  matrix[a][b] = 1
  matrix[b][a] = 1

print(ans)

Measured memory_bytes: 40944
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << c-d+b << ' ' << d+c-a << ' ' << a-d+b << ' ' << b+c-a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b,c,c5=0,c7=0;
  scanf("%d%d%d",&a,&b,&c);
  if(a==5)
    c5++;
  if(b==5)
    c5++;
  if(c==5)
    c5++;
  if((a==7 || b==7)||c==7)
    c7++;
  if(c5==2&&c7==1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int N = sc.nextInt();

		int answer = 0;

		//HashMap<Key,Value>
		Map<Integer, Integer> ForbiddenMap = new HashMap<>();

		if(N != 0) {
			for(int i = 0; i < N; i++) {
				int getNum = sc.nextInt();
				ForbiddenMap.put(getNum,getNum);
			}

			int num = 0;
			while(true) {
				if(ForbiddenMap.containsKey(X - num)) {
					//含まれてたら次
				}else {
					//
					answer = X-num;
					break;
				}
				if(ForbiddenMap.containsKey(X + num)) {
					//含まれてたら次
				}else {
					answer = X+num;
					break;
				}
				num++;
			}

		}else if(N == 0) {
			answer = X;
		}

		System.out.println(answer);

	}

}


Measured memory_bytes: 27132
use whiteread::parse_line;

fn main() {
    let (n, mut m): (usize, usize) = parse_line().unwrap();
    let mut ab: Vec<[usize; 2]> = Vec::new();
    let mut ans = 0;

    for _ in 0..n {
        let (ai, bi): (usize, usize) = parse_line().unwrap();
        ab.push([ai, bi]);
    }

    ab.sort_by_key(|x| x[0]);
    for [a, b] in ab {
        if m <= b {
            ans += a * m;
            break;
        } else {
            ans += a * b;
            m -= b;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4228
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    int[][] divisor = createDivisorTable(N);
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= i; j++) {
        divisor[0][j] += divisor[i][j];
      }
    }

    // 75 = (4+1)*(4+1)*(2+1)
    // 75 = (14+1)*(4+1)
    // 75 = (24+1)*(2+1)
    // 75 = 74+1
    int more74 = 0;
    int more24 = 0;
    int more14 = 0;
    int more4 = 0;
    int more2 = 0;
    for (int i = 1; i <= N; i++) {
      int a = divisor[0][i];
      if (a >= 74) more74++;
      if (a >= 24) more24++;
      if (a >= 14) more14++;
      if (a >= 4) more4++;
      if (a >= 2) more2++;
    }
    int ans = more74 + more24*(more2-1) + more14*(more4-1)
      + more4*(more4-1)*(more2-2) / 2; 
    System.out.println(ans);
  }
  
  private static int[][] createDivisorTable(int n) {

    int[][] d = new int[n+1][n+1];
    for (int i = 1; i <= n; i++) {
      boolean isPrime = true;
      for (int j = 2, work = i; j < i; j++) {
        while (work % j == 0) {
          isPrime = false;
          work /= j;
          d[i][j]++;
        }
      }
      if (isPrime) {
        d[i][i] = 1;
      }
    }
    return d;
  }
}

Measured memory_bytes: 23252
s=input().split("T")
X,Y=map(int,input().split())
x=list(map(len,s[::2]))
y=list(map(len,s[1::2]))
l=[x[0]]
s=set()
for i in x[1:]:
    s.clear()
    for j in l:
        s.add(j+i)
        s.add(j-i)
    l=list(s)
if(not X in l):
    print("No")
    quit()
l=[0]
for i in y:
    s.clear()
    for j in l:
        s.add(j+i)
        s.add(j-i)
    l=list(s)
if(not Y in l):
    print("No")
else:
    print("Yes")

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

typedef long long ll;
const int INF = 1 << 30;

int n, m;
vector<int> y(100010), p(100010);
vector<int> a[100010];

int main(){
    cin >> n >> m;

    for (int i = 0; i < m; i++){
        cin >> p[i] >> y[i];
        a[p[i]].push_back(y[i]);
    }

    for (int i = 1; i <= n; i++){
        sort(a[i].begin(), a[i].end());
    }

    for (int i = 0; i < m; i++){
        ll res;
        ll pre = p[i] * 1000000LL;
        ll epi = (int)(lower_bound(a[p[i]].begin(),
                                a[p[i]].end(), 
                                y[i]) 
                    - a[p[i]].begin()) + 1;
        res = pre + epi;
        cout << setw(12) << setfill('0') << res << endl;
    }
}

Measured memory_bytes: 7808
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String[] array = reader.readLine().split(" ");
            int N = Integer.parseInt(array[0]);
            long K = Long.parseLong(array[1]);
            int Q = Integer.parseInt(array[2]);

            int[] P = new int[N + 1];
            for (int i = 1; i <= Q; i++) {
                int n = Integer.parseInt(reader.readLine());
                P[n]++;
            }

            for (int i = 1; i <= N; i++) {
                if (K - Q + P[i] > 0) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            }
        }
    }

}


Measured memory_bytes: 39584
using System;
using System.Linq;

namespace AtCoder0621
{
	class Program
	{
		static void Main(string[] args)
		{
			B();
		}

		static void B()
		{
			var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			var k = ints[1];
			var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			Array.Sort(a);

			Console.WriteLine(a.Take(k).Sum());
		}

		static void A()
		{
			var s = Console.ReadLine();
			if (s == s.ToLower())
				Console.WriteLine('a');
			else
				Console.WriteLine('A');
		}
	}
}


Measured memory_bytes: 28504
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++) 
#define per(i , n , x)  for(int i = n ; i <= x ; i --) 
using namespace std ;
typedef long long ll ;
typedef pair<int , int> pii ;
const int inf = 0x3f3f3f3f ;
const int maxn = 2e5 + 5 ;
const int maxm = 1005 ;
int n ;
int cnt = 0 ;
ll a[maxn] , b[maxn] , num[maxn] ;
void init()
{
	for(int i = 1 ; i <= n ; i ++)
	{
		b[++ cnt] = a[i] ;
		num[cnt] = 1 ;
		if(a[i] == 0)
		{
			int j = i ;
			while(j + 1 <= n && a[j + 1] == a[j])  j ++ ;
			num[cnt] = j - i + 1 ;
			i = j ;
		}
	}
	n = cnt ;
}
int main()
{
	ll ans = 0 ;
	scanf("%d" , &n) ;
	for(int i = 1 ; i <= n ; i ++)  scanf("%lld" , &a[i]) ;
	init() ;
	for(int i = 1 ; i <= n ; i ++)
	{
		int up = min(i + 45 , n) ;
		ll sum1 = 0 , sum2 = 0 ;
		for(int j = i ; j <= up ; j ++)
		{
			sum1 ^= b[j] ;
			sum2 += b[j] ;
			if(sum1 == sum2)  
			{
				if(i == j && b[i] == 0)  ans += num[i] * (num[i] + 1) / 2 ;
				else  ans += num[i] * num[j] ;
			}			
		}
	}
	printf("%lld\n" , ans) ;
	return 0 ;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int x=100005;
int main()
{
int n;
cin>>n;
set<int> a;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
    a.insert(x);
}
cout<<a.size();
return 0;
}
 


Measured memory_bytes: 256
function main(input){
    let lines = input.split("\n");
    let i = 0;
    while(lines[i]!=="0 0"){
        render(lines[i]);
        i++;
        console.log();
    }

    
}
function render(line){
    let args = line.split(" ").map(x=>parseInt(x));
    let row = "";
    for(let i=0;i<args[1];i++){
        row += "#";
    }
    for(let i=0;i<args[0];i++){
        console.log(row);
    }
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 17856
using System;

class Range
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split();
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        int c = int.Parse(s[2]);

        if(a < b && b < c)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}


Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, s1, s2, s3;
  cin >> x;
  s1 = x / 100;
  s2 = (x - s1 * 100) / 10;
  s3 = x - s1 * 100 - s2 * 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i<=b;i++)
#define fore(i,a) for(auto &i:a)


using namespace std;
typedef long long ll;

const int MOD = 1e9 + 7;
string S;

void add(ll &a, ll b) {
	a += b;
	if (a >= MOD)a -= MOD;
}

//i番目までみた時の、状態j
//j=0 ""
//j=1 A
//j=2 AB
//j=3 ABC

ll dp[210000][4];

int main() {

	cin >> S;
	memset(dp, 0, sizeof(dp));

	dp[0][0] = 1;

	//Sを1文字ずつみていく。
	for (int i = 0; i < S.size(); ++i) {
		//Siを使わない。
		for (int j = 0; j < 4; ++j) {
			if (S[i] != '?') {
				add(dp[i + 1][j], dp[i][j]);
			}
			else {
				add(dp[i + 1][j], dp[i][j] * 3 % MOD);
			}
		}

		//Siを使う。

		//状態0はAか？がくれば状態1に遷移する。
		if (S[i] == 'A' || S[i] == '?') add(dp[i + 1][1], dp[i][0]);

		//状態1はBか？がくれば状態2に遷移する。
		if (S[i] == 'B' || S[i] == '?') add(dp[i + 1][2], dp[i][1]);

		//状態2はCか？がくれば状態3に遷移する。
		if (S[i] == 'C' || S[i] == '?') add(dp[i + 1][3], dp[i][2]);
	}
	
	cout << dp[S.size()][3] << endl;
}

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

using namespace std;

typedef long long ll;

ll x[64];

int main(int, char**)
{
	string s;
	ll n = 0, ans = 0;
	cin >> s;
	for (ll i = 0; i < s.length(); ++i) {
		if ((s[i] == 'A') ||(s[i] == 'T') 
		 || (s[i] == 'C') ||(s[i] == 'G')) {
			n++;
		} else {
			ans = max(n, ans);
			n = 0;
		}
	}
	ans = max(n, ans);
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void){
	uint16_t A,B,T;
	cin >> A >> B >> T;
	uint16_t res = 0;
	uint16_t Time = A;
	while(Time < (double(T + 0.5))){
		res += B;
		Time += A;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    priority_queue<ll> small;
    priority_queue<ll, vector<ll>, greater<ll>> large;
    ll smallSum = 0;
    ll largeSum = 0;
    ll bsum = 0;
    while (q--)
    {
        int hoge;
        cin >> hoge;
        // 要素aを追加
        if (hoge == 1)
        {
            ll a, b;
            cin >> a >> b;
            bsum += b;
            if (small.size() > large.size())
            {
                ll t = small.top();
                if (a >= t)
                {
                    large.push(a);
                    largeSum += a;
                }
                else
                {
                    small.pop();
                    smallSum -= t;
                    small.push(a);
                    smallSum += a;
                    large.push(t);
                    largeSum += t;
                }
            }
            else
            {
                if (small.empty())
                {
                    small.push(a);
                    smallSum += a;
                }
                else
                {
                    ll t = large.top();
                    if (a <= t)
                    {
                        small.push(a);
                        smallSum += a;
                    }
                    else
                    {
                        large.pop();
                        largeSum -= t;
                        large.push(a);
                        largeSum += a;
                        small.push(t);
                        smallSum += t;
                    }
                }
            }
        }
        // 中央値を求める
        else
        {
            ll x = small.top();
            ll ans = (x * (ll)small.size() - smallSum) + (largeSum - x * (ll)large.size()) + bsum;
            cout << x << ' ' << ans << endl;
        }
    }
}

Measured memory_bytes: 3828
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]

for i in range(n) :
    for j in range(l) :
        ans = 0
        for k in range(m) :
            ans += A[i][k] * B[k][j]
        if j == l-1 :
            print(ans)
        else :
            print(ans, end=" ")


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int x,y;cin>>x>>y;){
		cout<<x+y/2<<endl;
	}
}


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

int N,A[205];
int main()
{
  cin >> N;
  for(int i=0;i<2*N;i++)
    cin >> A[i];
  sort(A,A+2*N);

  long long ans = 0;
  for(int i=0;i<2*N;i+=2)
    ans+=A[i];

  cout << ans << '\n';
  
  return 0;
}


Measured memory_bytes: 256
n=int(input())
c=sorted(list(map(int, input().split())))
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if c[i] != c[j] and c[k] != c[i] and c[k] != c[j]:
                if c[i] + c[j] > c[k]:
                    ans += 1
print(ans)

Measured memory_bytes: 9104
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int k;
	int a = 1, b = 1, c = 1;
	long long d = 0;
	cin >> k;
	for (a = 1;a <= k;a++) {
		for (b = 1;b <= k;b++) {
			for (c = 1;c <= k;c++) {
				d+=__gcd(__gcd(a, b),c);
			}
		}
	}
	cout << d;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;

bool ok(int n){
  bool ans=false;
  while(n>1){
    if(n%2==1) ans=true;
    n/=2;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  if(!ok(n)) cout << "No" << endl;
  else{
    cout << "Yes" << endl;
    int now=0;
    int a[2*n-1],b[2*n-1];
    int s=(n-3)/4*4+3;
    for(int i=0;i<s-1;i++){
      a[now]=i; b[now]=i+1;
      now++;
    }
    a[now]=s-1; b[now]=n;
    now++;
    for(int i=0;i<s-1;i++){
      a[now]=n+i; b[now]=n+i+1;
      now++;
    }
    if(n%4==1||n%4==2){
      a[now]=0; b[now]=s; now++;
      a[now]=s; b[now]=s+1; now++;
      a[now]=0; b[now]=n+s+1; now++;
      a[now]=n+s+1; b[now]=n+s; now++;
    }
    if(n%4==2){
      a[now]=1; b[now]=n-1; now++;
      a[now]=2*n-2; b[now]=2*n-1; now++;
    }
    if(n%4==0){
      int x,y;
      for(int i=30;i>=0;i--){
        if(n&(1<<i)){
          x=i; break;
        }
      }
      x=(1<<x);
      y=(x^n);
      b[y-1]=x-1; a[y]=x-1;
      b[x-2]=y; a[x-1]=y;
      b[s+y-1]=n+x-1; a[s+y]=n+x-1;
      b[s+x-2]=n+y; a[s+x-1]=n+y;
      a[now]=y-1; b[now]=n-1; now++;
      a[now]=x-1; b[now]=2*n-1; now++;
    }
    for(int i=0;i<2*n-1;i++){
      cout << a[i]+1 << ' ' << b[i]+1 << endl;
    }
  }
}


Measured memory_bytes: 4352