akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    private static final String HIT = "HIT";
    private static final String HOMERUN = "HOMERUN";
    private static final String OUT = "OUT";
    private static final int MAX_OUT_COUNT = 3;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();sc.nextLine();
        int outCount = 0;
        int[] bases, points;
        bases = new int[3];
        points = new int[n];
        for (int i = 0; i < n; i++) {
            outCount = 0;
            clearBases(bases);
            while (outCount < MAX_OUT_COUNT) {
                switch (sc.nextLine()) {
                    case HIT:
                        points[i] = hit(points[i], bases);
                        break;
                    case HOMERUN:
                        points[i] = homerun(points[i], bases);
                        break;
                    case OUT:
                        outCount++;
                        break;
                    default:
                }
            }
        }
        ptint(points);
    }

    static void ptint(int[] ps) {
        for (int p : ps) {
            System.out.println(p);
        }
    }

    static int hit(int point, int[] bases) {
        for (int i = (bases.length - 1); i >= 0; i--) {
            if (bases[i] == 1) {
                switch (i) {
                    case 2:
                        bases[i] = 0;
                        point++;
                        break;
                    case 1:
                        bases[i] = 0;
                        bases[i + 1] = 1;
                        break;
                    case 0:
                        bases[i] = 0;
                        bases[i + 1] = 1;
                        break;
                }
            }
        }
        bases[0] = 1;
        return point;
    }

    static int homerun(int point, int[] bases) {
        for (int i = 0; i < bases.length; i++) {
            if (bases[i] == 1) {
                point++;
            }
        }
        point++;
        clearBases(bases);
        return point;
    }

    static void clearBases(int[] bases) {
        for (int i = 0; i < bases.length; i++) {
            bases[i] = 0;
        }
    }
}


Measured memory_bytes: 26360
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    string s;
    cin>>s;
    int c=0,m=0;;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
            c++;
        }
        else{
            c=0;
        }
        if(c>m){
            m=c;
        }

    }

    cout<<m<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL a(3*N); REP(i,3*N) cin >> a[i];
    sort(a.begin(),a.end(),greater<LL>());
    LL ans = 0;
    REP(i,N){
        ans += a[i*2+1];
    }
    cout << ans << endl;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mn(a, b) (a < b ? a : b)
#define mx(a, b) (a > b ? a : b)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define base 331

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int const MAXn = 1e5 + 2;

ll dp[MAXn];

int main(){

    //freopen(".in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, w;
    cin>>n>>w;
    fill(dp + 1, dp + MAXn - 1, 1e15);
    for(int i = 1; i <= n; i++){
        ll p, b;
        cin>>p>>b;
        for(int k = MAXn - 2; k - b >= 0; k--)
            dp[k] = mn(dp[k], dp[k - b] + p);
    }
    for(int i = MAXn - 2; i >= 1; i--){
        if(dp[i] <= w){
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    vector<ll> h(N);
    rep(i, 0, N) cin >> h[i];
    ll ans = 0;
    rep(i, 0, N){
        ans += h[i];
        rep(k, 0, h[i]){
            ll j = i+1;
            while(h[j] > 0){
                h[j]--;
                j++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

signed main() {
    int n;
    string s[3];
    cin >> n >> s[0] >> s[1] >> s[2];

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        set<char> se;
        for (int j = 0; j < 3; j++) {
            se.insert(s[j][i]);
        }
        cnt += se.size() - 1;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())

l = []

for i in range(h):
    l.append(list(input()))
flag = False

while not flag:
    f2=True
    for i in range(h):
        if len(set(l[i])) == 1 and l[i][0]=='.':
            l.pop(i)
            f2=False
            break
    
    h=len(l)
    w=len(l[0])

    for j in range(w):
        f3=True
        for i in range(h):
            f3 = f3 and l[i][j]=='.'
        if f3:
            for i in range(h):
                l[i].pop(j)
            f2=False
            break
    h=len(l)
    w=len(l[0])
    flag = f2

for i in range(len(l)):
    s = ''
    for j in range(len(l[0])):
        s+=l[i][j]
    print(s)


Measured memory_bytes: 40688
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 105;
const int MAXK = 100005;
const LL MOD = 1000000007;

int N, K, a[MAXN], dp[MAXK];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i];
	
	dp[0] = 1;
	for (int i = N - 1; i >= 0; i--) {
		int sum = 0;
		for (int j = K - a[i]; j <= K; j++) sum = (sum + dp[j]) % MOD;
		for (int j = K; j >= 0; j--) {
			int tmp = dp[j];
			dp[j] = sum;
			sum = (sum - tmp) % MOD;
			if (j - a[i] - 1 >= 0) sum = (sum + dp[j - a[i] - 1]) % MOD;
		}
	}
	
	cout << (dp[K] + MOD) % MOD << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
const ll INF = ll(1e18)+1;
int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    ll l = -INF,r = INF;
    while(r - l > 1){
        ll x = (l+r)/2;
        //ok:x未満となるペアがk個みまんかどうか
        bool ok = [&]{
            ll tot = 0;
            rep(i,n){
                if(a[i] < 0){
                    int left = -1,right = n;
                    while(right - left > 1){
                        int center = (right + left) /2;
                        if(a[center] * a[i] < x)right = center;
                        else left = center;
                    }
                    tot += n-right;
                }
                else {
                    int left = -1,right = n;
                    while(right - left > 1){
                        int center = (right + left) /2;
                        if(a[center] * a[i] < x)left = center;
                        else right = center;
                    }
                    tot += left+1;
                }
                if(a[i]*a[i] < x)tot--;
            }
            tot/=2;
            return tot < k;
        }();
        if(ok)l = x;
        else r = x;
    }
    cout << l << endl;

    return 0;
}

Measured memory_bytes: 1792
S = [""] * 3
S[0] = input()
S[1] = input()
S[2] = input()

count = [0] * 3
turn = 0

while count[turn] != len(S[turn]):
    temp = S[turn][count[turn]]
    count[turn] += 1
    turn = ord(temp) - ord("a")
    
print(chr(ord("A") + turn))

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
        if (b == 1) {
          // 出力
		  System.out.println(0);
        } else {
          int sum = a;
          int ans = 1;
          while(sum < b) {
            sum += a - 1;
            ans++;
          }
    
		// 出力
		System.out.println(ans);
        }
        
	}
}

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

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0.0;

  for(int i = 1; i <= n; i++) {
    int now = i;
    double tmp = 1.0;
    while(now < k) {
      tmp /= 2;
      now *= 2;
    }
    ans += tmp;
  }
  printf("%.12lf\n",ans/n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

vector< vl > adj(123456);
ll degree[123456]={0};
ll ston[123456];
//std::ios::sync_with_stdio(false);   
int dfs(int cur,int prev){
	ll i,sumi=0,maxi=0;
	if(adj[cur].size()==1)
		return 0;
	rep(i,adj[cur].size()){
		if(adj[cur][i]!=prev){
			dfs(adj[cur][i],cur);
		}
	}
	rep(i,adj[cur].size()){
		if(adj[cur][i]!=prev){
			sumi+=ston[adj[cur][i]];
			maxi=max(maxi,ston[adj[cur][i]]);
		}

	}
	ll x2=sumi-ston[cur];
	ll x1=2*ston[cur] -sumi;
	if(x1<0 || x2<0 || x2>sumi-maxi)
	{
		//cout<<x1<<" "<<maxi<<endl;
		cout<<"NO";
		exit(0);
	}

	ston[cur]=x1;
	if(prev==-1){
		if(ston[cur]){
			cout<<"NO";
		}
		else
			cout<<"YES";
	}
	return 0;
}
int main(){
	std::ios::sync_with_stdio(false);
	ll n,i,u,v;
	cin>>n;
	//int i;
	rep(i,n){
		cin>>ston[i];
	}
	if(n==2){
		if(ston[0]==ston[1])
			cout<<"YES";
		else
			cout<<"NO";
		return 0;
	}
	rep(i,n-1){
		cin>>u>>v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
		degree[u]++;
		degree[v]++;
	}
	rep(i,n){
		if(degree[i]!=1){
			break;
		}
	}
	//cout<<i<<endl;
	dfs(i,-1);
	//cout<<"YES"<<endl;
}



Measured memory_bytes: 13184
#include<iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    int count=0;
    for(int i=0;i<4;i++){
        if(s.at(i) == '+') count++;
        else if(s.at(i) == '-') count--;
    }
    cout << count << endl;
    return 0;
 }


Measured memory_bytes: 256
import java.util.Scanner;

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

       int n=scan.nextInt();
       /*0~12 S, 13~25 H, 26~38 C, 39~51 D*/
       boolean cards[] =new boolean[52];
       for(int i=0;i<52;i++){
           cards[i]=true;
       }
       for(int j=0;j<n;j++){
           String Mark=scan.next();
           int num=scan.nextInt();

           if (Mark.equals("S")) {
               cards[num-1]=false;
           }
           if (Mark.equals("H")) {
               cards[13+num-1]=false;
           }
           if (Mark.equals("C")) {
               cards[13*2+num-1]=false;
           }
           if (Mark.equals("D")) {
               cards[13*3+num-1]=false;
           }
       }
       for(int k=0;k<52;k++){
           if(cards[k]){
               if(k<13){
                   System.out.println("S "+(k+1));
               }else if(k>=13 && k<26){
                   System.out.println("H "+(k-12));
               }else if(k>=26 && k<39) {
                   System.out.println("C "+(k-25));
               }else if(k>=39){
                   System.out.println("D "+(k-38));
               }
           }
       }
    }
}



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

int main() {
    int A, B, C, K; cin >> A >> B >> C >> K;
    ll ans = A;
    if (A >= K) {
        cout << K << endl;
        return 0;
    }
    else  {
        K -= A;
        if (B >= K) {
            cout << ans << endl;
            return 0;
        }
        else {
            K -= B;
            cout << ans-K << endl;
            return 0;
        }
    }
}

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

using namespace std;

int main (void)
{
	string str;
	getline(cin, str);
	int len = str.length();
	int count = 0;
	
	for (int i = 0; i < len; i++){
		if(str[i] != str[len - i  -1])
			count++;
	}
	cout << count/2 << endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
main()
{
   int N, a[2000001];
   scanf("%d", &N);
   rep(i, N)scanf("%d", a+i);
   std::sort(a, a+N);
   rep(i, N)printf("%d%c", a[i], i+1 < N ? ' ' : '\n' );
}



Measured memory_bytes: 10488
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int gcd(int a, int b) {
    if(b < a) {
        int t = a;
        a = b;
        b = t;
    }
    if (b % a == 0) {
        return a;
    }
    return gcd(b % a, a);
}

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int v = gcd(a, b);
    int c = 0;
    for(int i=v; i>=1; i--) {
        if(v % i == 0) {
            c++;
            // cout << "v" << i << endl;
            if(c == k) {
                cout << i << endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int n,i,a[100]={0};
    scanf("%d",&n);
    
    for(i = 0;i < n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i = 0;i < n;i++)
    {
        printf("%d",a[n-i-1]);
        if(n-i-1 != 0)
        {
            printf(" ");
        }
        else puts("");
    }
    
    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){

    int X;
    cin >> X;
    for(int i = 1 ; i <= 360 ; i++){
        if((X*i)%360 == 0){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3628
#include<stdio.h>

int main(){
int m, f, r, x;
while(1){
  scanf("%d %d %d", &m, &f, &r);
  x = m + f;
  if(m == -1 && f == -1) break;
  if(m == -1 || f == -1) printf("F\n");
  else if(x >= 80) printf("A\n");
  else if(x >= 65) printf("B\n");
  else if(x >= 50) printf("C\n");
  else if(x >= 30 && r >= 50) printf("C\n");
  else if(x >= 30 && r < 50) printf("D\n");
  else printf("F\n");
}
return 0;
}



Measured memory_bytes: 2128
#include<cstdio>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
#include<stack>
#include<sstream>
#include<string>
using namespace std;
#define ll long long
#define N 300010
bool cmp(int a,int b)
{
    if(a%10==0)return 1;
    if(b%10==0)return 0;
    return (a%10)>(b%10);
}
int main()
{
   int a[5],ans=0;
   cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    sort(a,a+5,cmp);
    for(int i=0;i<4;i++)
        ans+=a[i]+(10-(a[i]%10))%10;
    ans+=a[4];
    cout<<ans;
       return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s,t;
    cin >>s >>t;
    ll ans = 0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i))ans++;
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 200005;


stack <ll> st;
ll a[MAXN];
ll l[MAXN];
ll r[MAXN];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    st.push(0);
    a[0] = 0;

    for (int i = 1; i <= n; i++)
    {
        while(a[st.top()] > a[i]) st.pop();
        l[i] = i - st.top();
        st.push(i);
    }

    st.push(n+1);
    a[n+1] = 0;

    for (int i = n; i >= 1; i--)
    {
        while(a[st.top()] > a[i]) st.pop();
        r[i] = st.top() - i;
        st.push(i);
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans += l[i]*r[i] * a[i];

    cout << ans;
    return 0;
}


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

void solve(long long a, long long b){
	string out = (a * b) % 2 ? "Odd" : "Even";
	cout << out << endl;
}

int main(){	
	long long a;
	long long b;
	scanf("%lld",&a);
	scanf("%lld",&b);
	solve(a, b);
	return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
if abs(N-M) >= 2:
  print(0)
  exit()
if abs(N-M) == 1:
  r = 1
else:
  r = 2
for i in range(1, N+1):
  r = r*i%1000000007
for i in range(1, M+1):
  r = r*i%1000000007
print(r)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll mod_pow(ll x,ll n,ll mod){
  if(!n)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<ll>());
  ll ans=0;
  ll d=mod_pow(2,n*2-1,MAX)*get_inv(2,MAX)%MAX;
  for(ll i=1; i<=n; i++) {
    ans+=(d+d*i)%MAX*a[i-1]%MAX;
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

typedef struct str_node node_t;
typedef struct str_node {
    int64_t id;
    int64_t cnt;
    vector<node_t*> next;
}node_t;
void dfs(vector<node_t> &node, int64_t from, int64_t to, int64_t x);
//void dfs(vector<node_t> &node, int64_t to, int64_t x);
int main(void) {
    int64_t N,Q;
    int64_t a,b;
    int64_t p,x;

    cin >> N >> Q;
    vector<node_t> node(N);
    for(int i=0;i<N;i++) {
        node[i].id = i;
        node[i].cnt = 0;
    }
    for(int i=1;i<N;i++) {
        cin >> a >> b;
        --a;--b;
        node[a].next.push_back(&node[b]);
        node[b].next.push_back(&node[a]);
    }

    for(int i=0;i<Q;i++) {
        cin >> p >> x;
        node[p-1].cnt += x;
    }

    dfs(node, -1, 0, 0);
    for(int i=0;i<N;i++) {
        cout << node[i].cnt << " ";
    }
    cout << endl;
    return 0;
}

void dfs(vector<node_t> &node, int64_t from, int64_t to, int64_t x) {
//void dfs(vector<node_t> &node, int64_t to, int64_t x) {
    node[to].cnt += x;
    for(int i=0;i<node[to].next.size();i++) {
        if(node[to].next[i]->id == from) continue;
        dfs(node,to,node[to].next[i]->id,node[to].cnt);
//        dfs(node,node[to].next[i]->id,node[to].cnt);
    }
}


Measured memory_bytes: 25856
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define sz size() 
using namespace std;
string s;
int t[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000},a=0,b=0;
int main(void){
	cin>>s;
	reverse(all(s));
	for(int i=0;i<s.sz;i++)a+=s[i]-'0';
	for(int i=0;i<s.sz;i++)b+=(s[i]-'0')*t[i];
//	cout<<a<<' '<<b<<endl;
	if(b%a)cout<<"No";
	else cout<<"Yes";
	return 0;
}

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

using ll = long long;

int main() {
    int N, M, a, b;
    cin >> N >> M;
    vector<int> d(N, 0);
    rep(i, M) {
        cin >> a >> b;
        d[a - 1]++;
        d[b - 1]++;
    }
    rep(i, N) {
        if (d[i] % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main(){
  int n, m;
  cin >> n >> m;
  vector<bool> broken(n + 1, false);
  for(int i = 0, temp; i < m; ++i){
    cin >> temp;
    broken[temp] = true;
  }
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  if(!broken[0]) dp[1] = 1;
  for(int i = 2; i <= n; ++i){
    if(!broken[i - 1]) dp[i] += dp[i - 1];
    if(!broken[i - 2]) dp[i] += dp[i - 2];
    dp[i] %= MOD;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int pow(int x)
{
    if (x > 1) return x-1;
    else return 13;
}
int main()
{
    int a,b;
    cin >> a >> b;
    if (pow(a) == pow(b)) printf("Draw\n");
    else if (pow(a) > pow(b)) printf("Alice\n");
    else printf("Bob\n");
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,n; cin>>h>>n;
  ll s=0;
  rep(i,n){
    ll a; cin>>a;
    s+=a;
  }
  if(s>=h) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 110;
int ans[Maxn][Maxn];
int h, w, n;
int main() {
	int i, j, k;
	scanf("%d%d%d", &h, &w, &n);
	i = 1; j = 1;
	for(k = 1; k <= n; k++){
		int x;
		scanf("%d", &x);
		while(x--){
			ans[i][j] = k;
			if(i&1){
				if(j < w) j++;
				else i++;
			} else {
				if(j > 1) j--;
				else i++;
			}
		}
	}
	for(i = 1; i <= h; i++) {
		for(j = 1; j < w; j++) printf("%d ", ans[i][j]);
		printf("%d\n", ans[i][w]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ << ' ' <<
#define squ(x)  ((x) * (x))
#define VAR_NAME(var)  cout << #var << " : ";
#define debug(var)  VAR_NAME(var); view(var);
#define max(v)  *max_element(v.begin(), v.end())
#define min(v)  *min_element(v.begin(), v.end())
#define sort(var)  std::sort(var.begin(), var.end());
#define rsort(var)  std::sort(var.begin(), var.end(), std::greater<>());
using namespace std;
using ll = long long;
int gcd(int m, int n){return !n ? m : gcd(n, m%n);}
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> void view(const T e){ std::cout << e << std::endl;}
template<typename T> void view(const vector<T>& v){ for(const auto& e : v) std::cout << e << " "; std::cout << std::endl; }
template<typename T> void view(const VV<T>& vv){ for(const auto& v : vv){ view(v); } }

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


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	m := map[rune]int{'a': 0, 'b': 0, 'c': 0}
	for _, c := range s {
		m[c]++
	}

	a, b, c := m['a'], m['b'], m['c']
	d := max(max(abs(a-b), abs(a-c)), abs(b-c))
	if d < 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

while True:
	H, W = map(int, input().split())
	if (not H) and (not W):
		break

	for i in range(H):
		if i == 0 or i == (H - 1):
			print('#' * W)
		else:
			print('#' + '.' * (W - 2) + '#')
    
	print()


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
const int N=100005; 

bool bl[N];

vector<int> G[N];
vector<int> tail;
vector<int> head;

 int main()
 {
	int n,m,i;
	scanf("%d%d",&n,&m);

	int a,b;
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	for(i=1;i<=n;i++) bl[i]=false;

	for(i=1;i<=n;i++)
	{
		if(G[i].size()>0) break;
	}

	tail.push_back(i);
	head.push_back(G[i][0]);

	bl[i]=true;
	bl[G[i][0]]=true;

	int v;
	v=tail[0];

	for(i=0;i<(int)G[v].size();i++)
	{
		if(!bl[G[v][i]])
		{
			tail.push_back(G[v][i]);
			v=G[v][i];
			bl[v]=true;
			i=-1;
		}
	}

	v=head[0];

	for(i=0;i<(int)G[v].size();i++)
	{
		if(!bl[G[v][i]])
		{
			head.push_back(G[v][i]);
			v=G[v][i];
			bl[v]=true;
			i=-1;
		}
	}

	printf("%d\n",(int)(tail.size()+head.size()));

	for(i=(int)tail.size()-1;i>=0;i--)
	{
		printf("%d ",tail[i]);
	}

	for(i=0;i<(int)head.size();i++)
	{
		printf("%d ",head[i]);
	}

	return 0;
 }


Measured memory_bytes: 6904
N=int(input())
#S=input()
#A,B,T=map(int,input().split())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
P=[V[i]-C[i] for i in range(N)]
ans=0
for i in P:
    if i>0:
        ans+=i
print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n = 0;
	cin >> n;
	ll arr[n];
	rep(i, n) {
		cin >> arr[i];
	}
	ll ans = 0;
	for(ll i = 1; i < n - 1; ++i) {
		if(arr[i - 1] < arr[i] && arr[i] < arr[i + 1]) {
			ans++;
		}
		else if(arr[i - 1] > arr[i] && arr[i] > arr[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

vector <char> v;

int main()
{
    string s;
    cin >> s;
    int ps = 0, pp = 0, cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'S') ps++;
        if(s[i] == 'T'){
            if(ps > 0) {
                ps--;
                cnt+=2;
            }
            else pp++;
        }
    }
    cout << s.size() - cnt <<endl;
}



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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
      
    int count;
    cin>>count;
    vector<long long int>ans;
    long long int total=0;
    for(int i=0;i<count;i++)
    {
      long long int first;
      cin>>first;
      total^=first;
      ans.push_back(first);
    }

    for(int i=0;i<count;i++)
    {
      cout<<(total^ans[i])<<" ";
    }
    cout<<endl;

    return 0;

}

Measured memory_bytes: 5292
/*
    Problem 18
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    int q;
    cin >> q;
    vector<int> t(q);
    for (int i = 0; i < q; i++) cin >> t[i];
    int ans = 0;
    // めぐる式二分探索
    // https://twitter.com/meguru_comp/status/697008509376835584
    for (int ti : t) {
        // 半開区間(ng, ok] or [ok, ng)
        int ok = n-1;  // s[ind] >= key を満たす最大のindex(含む)
        int ng = -1;  // s[ind] < keyを満たす最小のindex(含まない)
        // ok と ng のどちらが大きいかわからないことを考慮
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (s[mid] >= ti) ok = mid;  // 満たすならokの範囲を狭める
            else ng = mid;  // 満たさないならngの範囲を狭める
        }
        // okが s[ok] >= keyを満たす最小のindexとなる
        if (s[ok] == ti) ans++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3340
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		if (s.Substring(2, 1) == s.Substring(3, 1) && s.Substring(4, 1) == s.Substring(5, 1))
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}
	}
}


//string s = Console.ReadLine();
//int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = inputintArray[0];
//int W = inputintArray[1];
//int N = int.Parse(Console.ReadLine());
//int[] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

//Console.WriteLine(ans);

Measured memory_bytes: 13140
import sys
readline = sys.stdin.readline

sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    As = list(map(int, input().split()))

    query = (map(int, readline().strip().split()) for _ in range(N-1))

    tree = [[] for _ in range(N)]
    for u, v in query:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)

    inf = 10 ** 18
    dp = [inf] * (N+1)
    ans = [0] * N

    def dfs(node, parent):
        v = As[node]
        lb = binary_search(dp, v)
        old = dp[lb]
        dp[lb] = v
        ans[node] = binary_search(dp, inf)
        for child in tree[node]:
            if child == parent:
                continue
            dfs(child, node)
        dp[lb] = old

    dfs(0, 0)

    for k in range(N):
        print(ans[k])


def binary_search(seq, v):
    left = 0
    right = len(seq) - 1
    center = right // 2

    while left != right:
        if v <= seq[center]:
            right = center
        else:
            left = center+1
        center = (right + left) // 2

    return center


if __name__ == "__main__":
    main()


Measured memory_bytes: 284200
#include<stdio.h>

int main()
{
  int m, f, r, j, i=0;
  char a[1000];

  while(1){
    scanf("%d%d%d", &m, &f, &r);
    if(m == -1 && f == -1 && r == -1) break;
    else if(m == -1 || f == -1) a[i] = 'F';
    else if(m+f >= 80) a[i] = 'A';
    else if(m+f >= 65 && 80 > m+f) a[i] = 'B';
    else if(m+f >= 50 && 65 > m+f) a[i] = 'C';
    else if(m+f >= 30 && 50 > m+f && r >= 50) a[i] = 'C';
    else if(m+f >= 30 && 50 > m+f && r < 50) a[i] = 'D';
    else if(m+f < 30) a[i] = 'F';
    i++;
  }

  for(j = 0; j < i; j++){
    printf("%c\n", a[j]);
  }

  return 0;
}

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

Measured memory_bytes: 3736
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
int main(){
  ll n,k,l;cin>>n>>k>>l;
  UnionFind road(n);
  UnionFind train(n);
  rep(i,k){
    ll p,q;cin>>p>>q;
    road.unite(p-1,q-1);
  }
  rep(i,l){
    ll a,b;cin>>a>>b;
    train.unite(a-1,b-1);
  }
  vector<P>vec(n);
  rep(i,n){
    vec[i].first=road.root(i);
    vec[i].second=train.root(i);
  }
  map<P,ll>M;
  rep(i,n)M[vec[i]]++;
  rep(i,n)cout<<M[vec[i]]<<endl;
}

Measured memory_bytes: 18048
#include <stdio.h>
 
int main(int argc, const char * argv[])
{
 
    double ax, by, c, dx, ey, f;
    double x, y;
     
    while (scanf("%lf %lf %lf %lf %lf %lf", &ax, &by, &c, &dx, &ey, &f) != EOF) {
        y = (c * dx - ax * f) / (by * dx - ax * ey);
        x = (c - by * y) / ax;
        printf("%.3lf %.3lf\n", x, y);
    }
     
    return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  int count=0;
  for(int i=0; i<n; i++){
    cin >> h.at(i);
    if(h.at(i)>=k){
      count++;
    }
  }
  cout << count << endl;
}





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

int keta_goukei(int x) {
  int ret_val=0;
  while (0<x) {
    ret_val+=x%10;
    x/=10;
  }
  return ret_val;
}

int main() {
  int N; cin >>N;
  int ans=keta_goukei(N);
  cout <<(!(N%ans) ? "Yes":"No") <<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
w = list(map(int,input().split()))
s = sum(w)

s1 = 0

ans = 10**9
for i in range(n):
    s1 += w[i]
    s2 = s - s1
    dif = abs(s1 - s2)
    ans = min(dif,ans)
print(ans)



Measured memory_bytes: 3060
fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let n:usize = buf.trim().parse().unwrap();
    let mut parent = vec![-1; n];
    let mut children = vec![vec![]; n];
    for _ in 0..n {
        let mut buf = String::new();
        let _ = std::io::stdin().read_line(&mut buf).ok();
        let mut buf = buf.split_whitespace();
        let id: usize = buf.next().unwrap().parse().unwrap();
        let n_child: usize = buf.next().unwrap().parse().unwrap();
        for _ in 0..n_child {
            let p: usize = buf.next().unwrap().parse().unwrap();
            parent[p] = id as i64;
            children[id].push(p);
        }
    }
    let mut depths = vec![-1; n];
    for i in 0..n {
        if parent[i] == -1 {
            set_depth(0, &children, &mut depths, i);
        }
    }
    //println!("{:?}", parent);
    //println!("{:?}", children);
    //println!("{:?}", depths);
    for i in 0..n {
        print!("node {}: parent = {}, depth = {}, ", i, parent[i], depths[i]);
        if depths[i] == 0 {
            print!("root, [");
        } else if children[i].len() == 0 {
            print!("leaf, [");
        } else {
            print!("internal node, [");
        }
        for j in 0..children[i].len() {
            print!("{}", children[i][j]);
            if j != children[i].len() - 1 {
                print!(", ");
            }
        }
        println!("]");
    }
}

fn set_depth(depth: usize, children: &Vec<Vec<usize>>, depths: &mut Vec<i64>, id: usize) {
    depths[id] = depth as i64;
    for i in &children[id] {
        set_depth(depth+1, children, depths, *i);
    }
}



Measured memory_bytes: 13112
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint w, h, n;
llint x[100005], y[100005], x2[100005], y2[100005];
vector<P> vec[4];
stack<llint> stk;

bool check(llint x, llint y)
{
	return (x == 0 || y == 0 || x == w || y == h);
}

void add(llint x, llint y, llint id)
{
	llint to;
	if(y == 0) to = 0;
	else if(y == h) to = 2;
	else if(x == 0) to = 3;
	else if(x == w) to = 1;
	
	if(to % 2) vec[to].push_back(P(y, id));
	else vec[to].push_back(P(x, id));
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> w >> h >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> x2[i] >> y2[i];
	
	for(int i = 1; i <= n; i++){
		if(check(x[i], y[i]) && check(x2[i], y2[i])){
			add(x[i], y[i], i), add(x2[i], y2[i], i);
		}
	}
	sort(vec[0].begin(), vec[0].end());
	sort(vec[1].begin(), vec[1].end());
	sort(vec[2].rbegin(), vec[2].rend());
	sort(vec[3].rbegin(), vec[3].rend());	
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < vec[i].size(); j++){
			if(stk.size() && stk.top() == vec[i][j].second) stk.pop();
			else stk.push(vec[i][j].second);
		}
	}
	if(stk.size()) cout << "NO" << endl;
	else cout << "YES" << endl;
	
	return 0;
}

Measured memory_bytes: 8036
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var nx = IO.RSInt;
            var x = IO.RSInt;

            var sub = new int[nx[0]];
            for (int i = 0; i < nx[0]; i++)
            {
                sub[i] = Abs(nx[1] - x[i]);
            }

            Array.Sort(sub);
            Array.Reverse(sub);

            for (int i = 0; i < nx[0] - 1; i++)
            {
                sub[i + 1] = GCD(sub[i], sub[i + 1]);
            }

            WriteLine(sub.Last());
        }

        public static int GCD(int x, int y)
        {
            if (x < y) Swap(ref x, ref y);
            if (y == 0) return x;
            else return GCD(x % y, y);
        }

        public static void Swap(ref int x, ref int y)
        {
            int tmp = x;
            x = y;
            y = tmp;
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

int main(){
    int five = 0 , seven = 0 , n;
    
    for(int i = 0 ; i< 3 ; i++)
    {
        cin >> n;
        if(n == 5)
        {
            five++;
        }
        else if(n==7)
        {
            seven++;
        }
    }
    
    if(seven == 1 && five ==2)
    {
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF 1<<30
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int V; cin >> V;
	vector<vector<pair<int, int>>> g(V);
	vector<int> dp(V);
	queue<int> q;

	//input
	for (int i = 0; i < V; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int c, v;
			cin >> c >> v;
			g[u].push_back(make_pair(c, v));
		}
	}

	//initialize
	fill(dp.begin(), dp.end(), INF);
	dp[0] = 0;
	q.push(0);

	//Dijkstra
	while (!q.empty()) {
		int k = q.front(); q.pop();
		for (int i = 0; i < g[k].size();i++) {
			int next = g[k][i].first;
			int w = g[k][i].second;
			if (dp[k] + w < dp[next]) {
				dp[next] = dp[k] + w;
				q.push(next);
			}
		}
	}

	//output
	for (int i = 0; i < V;i++) {
		cout << i << " " << dp[i] << endl;
	}
}

Measured memory_bytes: 3184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		char[] c = s.toCharArray();
		for(int i = 0; i < k; i++) {
			if(c[i]!='1') {
				System.out.println(c[i]);
				System.exit(0);
			}
		}System.out.println('1');
	}
}

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

int main(){
  int N , M ;
  cin >> N >> M ;
  int ansac=0;
  int answa=0;
  vector<int> AC(103000,0);
  vector<int> WA(103000,0);
  
  for(int i=0;i<M;i++){
    int s ;
    string p ;
    cin >> s >> p ;
    if(p=="AC"&&AC[s]==0){
      ansac++;
      AC[s]++;
      answa += WA[s];
    }
    else if(p=="WA"){
     WA[s]++;
    }
  }
    
    cout << ansac << ' ' << answa << endl;
    
  }




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
bool a2[111];
int ans=0;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		int a;
		cin>>a;
		for(int c=0;c<a;c++)
		{
			int b;
			cin>>b;
			a2[b]=1;
		}
	}
	for(int i=1;i<=n;i++)
		if(a2[i]==0)
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int C = sc.nextInt();
		final int D = sc.nextInt();
		final int E = sc.nextInt();
		int count = 0;
		int state = A;
		if (state < 0) {
			count = -(A * C);
			state = 0;
		} 
		if (state == 0) {
			count += D;
		} 
		if (0 <= state) {
			count += E * (B - state);
			state = B;
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26248
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int h = scanner.nextInt();
		System.out.println((a+b)*h/2);
	}
}


Measured memory_bytes: 21844