akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

// B - ROT N
// https://atcoder.jp/contests/abc146/tasks/abc146_b
public class Main {

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

        int N = Integer.parseInt(scanner.next());
        char[] S = scanner.next().toCharArray();

        scanner.close();

        for (char c : S) {
            int tmp = c + N;
            if (tmp <= 90) {
                System.out.print((char) tmp);
            } else {
                System.out.print((char) (tmp % 90 + 64));
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod


int main(){
    ll N; cin>>N;
    vec d(100003,0);
    ll SUM=0;
    rep(i,N){
        ll x; cin>>x; SUM+=x;
        d[x]++;
    }
    ll Q; cin>>Q;
    vec ans;
    rep(i,Q){
        ll b,c; cin>>b>>c;
        SUM+=(c-b)*d[b];
        ans.pb(SUM);
        d[c]+=d[b];
        d[b]=0;
    }
    rep(i,Q) cout<<ans[i]<<endl;

}

Measured memory_bytes: 5100
#include <stdio.h>

int main(){
 int n, i, max, min;
 long long int sum;
 scanf("%d",&n);
 int a[n];
 for(i = 0; i < n; i++)
  scanf("%d",&a[i]);
 
 max = a[0];
 min = a[0];
 sum = 0;

 for(i = 0; i < n; i++){
  if(a[i] > max)
    max = a[i];
  if(a[i] < min)
    min = a[i];

  sum += a[i];
 } 
 printf("%d %d %lld\n",min, max, sum);
 
 return 0;
} 

Measured memory_bytes: 640
import java.util.*;
  
 public class Main {
 	public static void main(String[] args) {
 		// practice contest
  
 		Scanner sc = new Scanner(System.in);
 		String s = sc.next();

		String[] d = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
		int i;

		for (i = 0; i < d.length; i++) {
			if (s.equals(d[i])) {
				System.out.println(7 - i);
 			}
 		}
 	}
}


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

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N= 3e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll n,i,j,s=0;
    cin>>n;
    ll a[n];
    f(i,0,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll ans=INF;
    f(i,a[0],a[n-1]+1)
    {
         ll z=0;
        f(j,0,n)
        {
            z+=(i-a[j])*(i-a[j]);

        }
        ans=min(ans,z);
    }
    cout<<ans<<'\n';
}
int main()
{
   IOS();
   
   test_case();
   return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var S []string
var h, w int

func main() {
	sc.Split(bufio.ScanWords)
	h, w = nextInt(), nextInt()
	S = make([]string, h)

	for i := 0; i < h; i++ {
		S[i] = nextStr()
	}

	l := []int{1, 0, -1, 0}
	m := []int{0, 1, 0, -1}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if string(S[i][j]) == "#" {
				for k := 0; k < 4; k++ {
					x := i + l[k]
					y := j + m[k]
					if x >= 0 && x < h && y < w && y >= 0 {
						if string(S[x][y]) == "#" {
							break
						} else {
							if k == 3 {
								fmt.Println("No")
								return
							}
						}
					}
				}
			}
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 640
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():

    n, k = input_int_list()
    H = []
    for _ in range(n):
        H.append(input_int())
    H = sorted(H)
    ans = float("inf")
    for i in range(n - k + 1):
        ans = min(ans, H[i + k - 1] - H[i])
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 77336
import math
N = int(input())
C, S, F = [], [], []
for i in range(N-1):
    _c, _s, _f = map(int, input().split())
    C.append(_c)
    S.append(_s)
    F.append(_f)

ans = [0] * N
for i in range(N-1):
    for j in range(i+1):
        ans[j] = max(S[i], math.ceil(ans[j]/F[i]) * F[i]) + C[i]

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


Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
const ll INF = LONG_MAX;

struct xy {
  ll x, y;
};

int N, K;
vector<ll> x, y;
vector<xy> xy_comb;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  x.resize(N);
  y.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }

  xy_comb.resize(N * N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      xy_comb[i * N + j] = xy{x[i], y[j]};
    }
  }

  ll ans = INF;
  for (int i = 0; i < N * N; i++) {
    for (int j = i + 1; j < N * N; j++) {
      ll x_min = min(xy_comb[i].x, xy_comb[j].x);
      ll x_max = max(xy_comb[i].x, xy_comb[j].x);
      ll y_min = min(xy_comb[i].y, xy_comb[j].y);
      ll y_max = max(xy_comb[i].y, xy_comb[j].y);

      int k = 0;
      for (int i = 0; i < N; i++) {
        if (x_min <= x[i] && x[i] <= x_max && y_min <= y[i] && y[i] <= y_max) {
          k++;
        }
      }

      if (k >= K) {
        ans = min(ans, (x_max - x_min) * (y_max - y_min));
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  double a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<a*b/2<<' ';
  if(c==a/2 && d==b/2)
    cout<<1;
  else
    cout<<0;
  return 0;
}

Measured memory_bytes: 256
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;

vector<pair<int, int> > g[N];
int ans[N];

void dfs(int u = 1, int p = 0, int pc = 0) {
    int cur = 1;
    for (auto &e : g[u]) {
        int v, id;
        v = e.first;
        id = e.second;
        if (v == p) continue;
        if (cur == pc) ++cur;
        dfs(v, u, ans[id] = cur++);
    }
}

int main() {
    int n = read();
    for (int i = 1; i < n; ++i) {
        int u = read(), v = read();
        g[u].emplace_back(v, i);
        g[v].emplace_back(u, i);
    }
    int k = 0;
    for (int i = 1; i <= n; ++i) {
        k = max(k, (int) g[i].size());
    }
    dfs();
    cout << k << '\n';
    for (int i = 1; i < n; ++i) {
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 9856
#include<cstdio>  
#include<cstdlib>  
#include<cstring>  
#include<cmath>  
#include<algorithm>  
#define eps 1e-8  
using namespace std;  
struct point{  
    double x,y;  
}A[310];  
double dist(point a,point b){  
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));  
}  
void getmid(point p1,point p2,point &center){//????????????????????????????????????  
    point mid;  
    mid.x=(p1.x+p2.x)/2.0;mid.y=(p1.y+p2.y)/2.0;  
    double angle=atan2(p1.x-p2.x,p2.y-p1.y);  
    double dcm=sqrt(1-dist(p1,mid)*dist(p1,mid));  
    center.x=mid.x+dcm*cos(angle);center.y=mid.y+dcm*sin(angle);  
}  
int main()  
{  
    int n,i,j,k;  
    while(scanf("%d",&n),n){  
        for(i=0;i<n;++i){  
            scanf("%lf%lf",&A[i].x,&A[i].y);  
        }  
        int ans=1;  
        for(i=0;i<n;++i){  
            for(j=i+1;j<n;++j){  
                if(dist(A[i],A[j])>2.0)continue;  
                point center;  
                getmid(A[i],A[j],center);  
                int cnt=0;  
                for(k=0;k<n;++k){  
                    if(dist(A[k],center)<1.0+eps)cnt++;  
                }  
                ans=max(ans,cnt);   
            }  
        }  
        printf("%d\n",ans);  
    }  
    return 0;  
} 

Measured memory_bytes: 3056
#include <stdio.h>
#include <math.h>
int main(){
  double a,b,c,d,e,f;
  double x,y,X,Y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x=(e*c-b*f)/(a*e-b*d);
    y=(d*c-a*f)/(b*d-a*e);
    X=x*pow(10,4);
    Y=y*pow(10,4);
    X=(double)(int)(X+0.5);
    Y=(double)(int)(Y+0.5);
    printf("%.3f %.3f\n",X*pow(10,-4),Y*pow(10,-4));
  }
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
using namespace std;
int main()
{
	int d, r;
	while (1)
	{
		cin>>d>>r;
		if (d ==0 && r == 0)
			break;
		else
		{
			for (int i =0; i < d;i++)
			{
				for (int j=0;j <r;j++)
				{
					if (i == 0 || i == d -1 || j == 0 || j == r - 1)
						cout<<"#";
					else
						cout<<".";
				}
				cout<<endl;
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      String s = scanner.next();
      int a = count(s, 'R', n);
      int b = count(s, 'B', n);
      if (a > b) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    } finally {
      scanner.close();
    }
  }

  private static int count(String s, char c, int n) {
    int result = 0;
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == c) result++;
    }
    return result;
  }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n=s.length();
	s=s+'/';

	vector<ll> v;
	if(s[0]=='>') v.push_back(0);
	ll cnt=1;
	for(int i=1; i<=n; i++){
		if(s[i]!=s[i-1]){
			v.push_back(cnt);
			cnt=1;
		}else cnt++;
	}
	if(s[n-1]=='<') v.push_back(0);

	ll a=0;
	for(int i=0; i<v.size(); i+=2){
		a+=v[i]*v[i]+v[i+1]*v[i+1]+abs(v[i]-v[i+1]);
	}
	cout << a/2 << endl;
	return 0;
}

Measured memory_bytes: 3348
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll r, g, b;
    cin >> r >> g >> b;

    if((r * 100 + g * 10 + b) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(BigInt,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  a=pI(readline())
  b=pI(readline())
  if a>b
    println("GREATER")
  elseif a<b
    println("LESS")
  else
    println("EQUAL")
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 114036
import java.util.*;

public class Main {

  public static void main(String args[])
  {
    	Scanner sc = new Scanner(System.in);
    	String input = sc.nextLine();
    	String[] inputs = input.split(" ");
    	int row = Integer.valueOf(inputs[0]);
    	int col  = Integer.valueOf(inputs[1]);
    	long rowLong = Long.valueOf(row);
    	long colLong = Long.valueOf(col);
    	if(row ==1 && col==1) 
        {
          System.out.println('1');
          return;
        }
    	
    
    
    	if( (col== 2 ) || (row==2))
        {
          System.out.println('0');
          return;
        }
    	
    	if( row == 1) 
        {
          System.out.println(col-2);
          return;
        }
    	
    	if(col == 1)
        {
          System.out.println(row-2);
          return;
        }
    	
    	System.out.println( (rowLong-2)*(colLong-2));
  }
  
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a(n);
    rep(i,n){
        if(s[i] == 'R') a[i] = 0;
        if(s[i] == 'G') a[i] = 1;
        if(s[i] == 'B') a[i] = 2;
    }
    vector<int> cnt(3);
    rep(i,n) cnt[a[i]]++;
    ll ans = 1;
    rep(i,3) ans *= cnt[i];
    rep(j,n)rep(i,j){
        int k = j + (j - i);
        if(k < n){
            if(a[i] == a[j]) continue;
            if(a[i] == a[k]) continue;
            if(a[j] == a[k]) continue;
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	string s;
	cin >> s;
	if(s[s.size()-1]!='s')
		cout<<s<<'s'<<endl;
	else
		cout<<s<<"es"<<endl;
	return 0;
}

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

int main(){
    char x;
    cin >> x;
    int c1 = x - 'a';
    int c2 = x - 'A';

    if(c1 < 26 && c1 >= 0){
        cout << "a" << endl;
    }

    if(c2 < 26 && c2 >= 0){
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    K, A, B = LI()
    result = 0
    # 交換する価値もない
    if A >= B - 1:
        # 割りまくる
        result = K + 1
        print(result)
        return

    # 交換をできるだけする
    # 最初に円にできるまでにどれだけかかるか？？
    times_to_first_yen = A - 1
    # K - times_to_first_yenはひたすら交換しまくる
    remaining_times = K - times_to_first_yen
    result += (remaining_times // 2) * (B - A) + A
    # 端数の処理をする
    if remaining_times % 2 != 0:
        result += 1

    print(result)


main()


Measured memory_bytes: 6480
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];

    vector<int> y(M);
    for (int i = 0; i < M; i++) cin >> y[i];

    x.push_back(X);
    y.push_back(Y);

    int xx = *max_element(x.begin(), x.end());
    int yy = *min_element(y.begin(), y.end());

    bool good = false;
    for (int Z = -100; Z <= 100; Z++) {
        if (xx < Z && Z <= yy) good = true;
    }

    if(good) cout << "No War";
    else cout << "War";

    return 0;
}











































































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (ll)(1ll<<60)
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

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

	vector<ll> howmany;
	ll x = n;
  	for(ll i = 2; i * i <= x; i++){
    	bool in=false;
		ll cnt=0;
		while(n % i== 0) {
      		n /= i;
			in=true;
			cnt++;
    	}
		if(in){
			howmany.push_back(cnt);
		}
  	}

	if(n!=1){ 
		howmany.push_back(1);
	}

	ll ans=0;
	rep(i,howmany.size()){
		ll number=howmany[i],cnt=0,ins=0;

		while(cnt<=number){
			ans++;
			ins++;
			cnt+=ins;
		}
		ans--;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3628
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	cout<<unique(all(in))-in.begin()<<endl;
}











Measured memory_bytes: 256
def main():
    N, M = map(int, input().split(" "))
    foods = [0] * (M + 1)
    result = 0
    for _ in range(N):
        tmp = list(map(int, input().split(" ")))
        for t in tmp[1:]:
            foods[t] += 1
    for food in foods:
        if food == N:
            result += 1
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lim 999999999
#define on 100005
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR for(int i=1;i<=n;i++)
typedef long long int lo; 
typedef pair<int,int> PII;
int n,m,a[200005],cev=-lim,buy,kuc,say,k,z,x,y,mn=lim;
char c;
string s;
stack<int> st;
vector<int> v;
int main(){
	scanf("%d %d %d %d",&n,&m,&k,&z);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cev=max(cev,x);
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&y);
		mn=min(mn,y);
	}
	if(mn<=cev || mn<=k || cev>=z){
		printf("War");
		return 0;
	}
	printf("No War");
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int v = 4;
	int a[v] = {0, 0, 0, 0};
	string b[v] = {"AC", "WA", "TLE", "RE"};
	string s;
	for(int i = 0; i<n; i++){
		cin >> s;
		if(s == b[0])
			a[0]++;
		if(s == b[1])
			a[1]++;
		if(s == b[2])
			a[2]++;
		if(s == b[3])
			a[3]++;
		}	
		for(int i = 0; i<v; i++)
			cout << b[i] << " x " << a[i]<<endl;
	
	
	return 0;
	}


Measured memory_bytes: 3636
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=set()
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

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

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
	for ( int i = 0; i < N; i++) {
		for ( int j = N - 1; j >= i + 1; j--){
			if ( A[j].value < A[j - 1].value ) {
				Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++ ) {
			if ( A[j].value < A[minj].value ) minj = j;
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print(struct Card A[], int N) {
	for (int i = 0; i < N; i++ ) {
		if (i > 0 ) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0; i < N; i++) {
		if ( C1[i].suit != C2[i].suit ) return false;
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int N;
	char ch;

	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> C1[i].suit >> C1[i].value;
	}

	for (int i = 0; i < N; i++ ) C2[i] = C1[i];

	bubble(C1, N);
	selection(C2, N);

	print(C1, N);
	cout << "Stable" << endl;
	print(C2, N); if ( isStable(C1, C2, N) ) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
n = int(raw_input())
heap = map(int,raw_input().split(' '))

for i in range(len(heap)):
    j = i+1
    nid = j
    key = heap[j-1]
    pid = j/2-1
    if pid >= 0:
        p = heap[pid]
    lid = j*2-1
    rid = j*2
    if lid < len(heap):
        l = heap[j*2-1]
    if rid < len(heap):
        r = heap[j*2]
    print "node %s:" % nid,
    print "key = %s," % key,
    if pid >= 0:
        print "parent key = %s," % p,
    if lid < len(heap):
        print "left key = %s," % l,
    if rid < len(heap):
        print "right key = %s," % r,
    print ''

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

using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    int q; cin >> q;
    deque<char> dp;

    for (int i = 0; i < s.size(); i++) {
        dp.push_back(s[i]);
    }
    
    bool rev = false;
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) rev = !rev;
        else {
            int f; cin >> f;
            char c; cin >> c;

            if (f == 1) {
                if (rev) dp.push_back(c);
                else dp.push_front(c);
            } else {
                if (rev) dp.push_front(c);
                else dp.push_back(c);
            }
        }
    }
    if (rev) {
        for (int i = dp.size()-1; i >= 0; i--) {
            cout << dp[i];
        }
    } else {
        for (int i = 0; i < dp.size(); i++) {
            cout << dp[i];
        }
    }
    cout << endl;

}


Measured memory_bytes: 896
import java.util.*;
public class Main {
    static final long MODVAL = 998244353L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        System.out.println(String.format("%d %d %d", C, A, B));
    }
}


Measured memory_bytes: 22740
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

struct card {
  char suit, value;
  int pos;
};

typedef vector<card> vc;

void bubbleSort(vc& C, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N-1; j > i; j--) {
      if (C[j].value < C[j-1].value) swap(C[j], C[j-1]);
    }
  }
}

void selectionSort(vc& C, int N) {
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (C[j].value < C[minj].value) minj = j;
    }
    if (i != minj) swap(C[i], C[minj]);
  }
}

void dump(vc& C) {
  bool stable = true;
  string sp = "";
  for (int i = 0; i < sz(C); i++) {
    cout << sp << C[i].suit << C[i].value;
    sp = " ";
    if (i > 0
        && C[i-1].value == C[i].value
        && C[i-1].pos > C[i].pos) {
      stable = false;
    }
  }
  cout << endl;
  cout << (stable ? "Stable" : "Not stable") << endl;
}
int main(int argc, char **argv)
{
  int N;
  cin >> N;
  vc C(N);
  int i = 0;
  for (auto& c:C) {
    string s;
    cin >> s;
    c.suit = s[0];
    c.value = s[1];
    c.pos = i++;
  }

  vc C1(C), C2(C);
  bubbleSort(C1, N);
  selectionSort(C2, N);

  dump(C1);
  dump(C2);

  return 0;
}

Measured memory_bytes: 3176
import math
n,d=map(int,input().split())
xy=[map(int,input().split()) for _ in range(n)]
x,y=[list(i) for i in zip(*xy)]
count=0

for i in range(n):
    a=math.sqrt((x[i]*x[i])+(y[i]*y[i]))
    if d>=a:
        count=count+1   

print(count)


Measured memory_bytes: 116676
#include <bits/stdc++.h> 
  using namespace std; 
  #define ll long long
  int main()
  {
    int g,n,sum=0;
    cin>>g>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
 for(int i=0;i<n;i++)
    {
      sum+=a[i];
    }
    if(sum>=g)cout<<"Yes";
    else cout<<"No";
  }


  

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int a[200000];

int main()
{
    int n;
    cin >> n;
    vector<int> err(n);
    rep(i, n) {
        cin >> a[i];
        err[i] = i - a[i];
    }
    sort(err.begin(), err.end());
    ll ans = 0;
    rep(i, n) {
        ans += upper_bound(err.begin(), err.end(), i + a[i])
             - lower_bound(err.begin(), err.end(), i + a[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define EPS 1e-8
#define EQ(a) (-EPS<a && a<EPS)
#define MP make_pair

struct line{P a,b;};

double dot(P a,P b){
  return (conj(a)*b).real();
}
double cross(P a,P b){
  return (conj(a)*b).imag();
}
double po(P a){
  return a.real()*a.real() + a.imag()*a.imag();
}

// http://www.deqnotes.net/acmicpc/2d_geometry/lines
double distance(line a,P b){
  if ( dot(a.b-a.a, b-a.a) < EPS ) return po(b-a.a);
  if ( dot(a.a-a.b, b-a.b) < EPS ) return po(b-a.b);
  double t = abs( cross(a.b-a.a, b-a.a) );
  return t*t / po(a.b-a.a);
}

// http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm
bool intersect(line a,line b){
  double x,y;
  x = cross(a.b-a.a, b.a-a.a);
  y = cross(a.b-a.a, b.b-a.a);
  if(EQ(x)&&EQ(y))return false;
  if(x*y>EPS)return false;
  x = cross(b.b-b.a, a.a-b.a);
  y = cross(b.b-b.a, a.b-b.a);
  if(EQ(x)&&EQ(y))return false;
  if(x*y>EPS)return false;
  return true;
}

int main(){
  int n;
  scanf("%d",&n);
  if(n>5100){ // (101*101-1)/2 = 10200/2 = 5100
    // law of "su of hato"
    cout << "0.0000000" << endl;
    return 0;
  }
  assert(n <= 5100);
  // O(N^2) ~ O(1e8)
  line lines[n];
  double result = 114514.0;
  REP(i,n){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    lines[i] = (line){P(a,b),P(c,d)};
  }
  REP(i,n)REP(j,i){
    line a = lines[i], b = lines[j];
    if(intersect(a,b)){
      cout << "0.0000000" << endl;
      return 0;
    }
    result = min(result,
      min(min(distance(a,b.a), distance(a,b.b)),
          min(distance(b,a.a), distance(b,a.b))) );
  }
  cout.precision(10);
  cout << fixed << sqrt(result) << endl;
  return 0;
}

Measured memory_bytes: 1440
import math
import numpy as np
import itertools

def LI():
  return [int(s) for s in input().split()]

def distance(x1,x2):
  return math.sqrt((x1[0] - x2[0])**2 + (x1[1] - x2[1])**2)

def roots_distance(roots):
  dist = 0
  for i in range((len(roots)-1)):
    dist+=distance(locates[roots[i]],locates[roots[i+1]])
    
  return dist

N = int(input())

locates = np.array([LI() for i in range(N)])

dist = 0
count = 0
for roots in itertools.permutations(range(N),N):
  dist+=roots_distance(roots)
  count+=1
  
print(dist / count)

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

long long *a{};
int n, k;

bool need(long long, long long, int, int);

int main()
{
	scanf("%d%d", &n, &k);
	a = new long long[n];
	for (int i = 0; i < n; i++) scanf("%lld", a + i);
	std::sort(a, a + n, std::greater<long long>());
	int left{-1}, right{n};
	while (left + 1 < right)
	{
		int mid{(left + right) / 2};
		if (need(k - a[mid], k, n - 1, mid)) left = mid;
		else right = mid;
	}
	printf("%d\n", n - left - 1);

	delete[] a;
	return 0;
}

bool need(long long left, long long right, int a_index, int ignore)
{
	if (left <= 0 && right > 0) return true;
	if (a_index == -1 || right <= 0) return false;

	if (a_index == ignore)
		return need(left, right, a_index - 1, ignore);
	// 連結なら連結したやつを渡す
	if (right - a[a_index] >= left)
		return need(left - a[a_index], right, a_index - 1, ignore);
	// 非連結なら[left, right)に
	return need(left, right, a_index - 1, ignore) || need(left - a[a_index], right - a[a_index], a_index - 1, ignore);
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int x;
        Scanner input = new Scanner(System.in);
        x = input.nextInt();
        String s = Integer.toString(x);
        if (x >= 10 && x <= 99) {
            if (s.contains("9")) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  ll ans = 1;
  for(int i = 1; i < n + 1; i++)
  {
    ans = ans * i % MOD;
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 256
//Name: Find the Outlier
//Level: 
//Category:
//Note:

/**
 */
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;

    vector<double> ys(N+3);
    for(int i = 0; i < N+3; ++i) {
        cin >> ys[i];
    }
    const int CHECKER = N+2;
    int candidate = CHECKER;
    for(int outlier = 0; outlier <= N+1; ++outlier) {
        double c = 0;
        // term for generate f(i)
        for(int i = 0; i <= N+1; ++i) {
            if(i == outlier) continue;
            double tmp = 1;
            for(int j = 0; j <= N+1; ++j) {
                if(j == i || j == outlier) continue;
                tmp *= static_cast<double>(CHECKER - j) / (i - j);
            }
            c += tmp * ys[i];
        }
        //cout << c << ' ' << ys[CHECKER] << endl;
        if(fabs(c - ys[CHECKER]) < 0.9) {
            candidate = outlier;
            break;
        }
    }
    cout << candidate << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int INF = 1e9;
 
int main()
{
  int a, b;
  fscanf(stdin, "%d %d", &a, &b);
  while (b) {
    int c = a % b;
    a = b;
    b = c;
  }
  fprintf(stdout, "%d\n", a);
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

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

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

int main()
{
    ll Q, H, S, D; cin >> Q >> H >> S >> D;
    ll N; cin >> N;
    Q *= 4, H *= 2;
    ll two_l = (N / 2) * min(2 * Q, min(2 * H, min(2 * S, D)));
    ll one_l = (N % 2) * min(Q, min(H, S));
    ll ans = two_l + one_l;
    cout << ans << endl;
}

Measured memory_bytes: 256
#n,d=map(int,input().split())
#xy = [list(map(int,input().split())) for i in range(n)]
k=int(input())
ans=0
flag=True
for i in range(0,10**6+1):
  ans= ((ans%k)*(10%k))%k+7%k
  ans=ans%k
  if ans==0:
    print(i+1)
    flag=False
    break
if flag:
  print(-1)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 2100;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    LL s;
    cin>>s;
    LL dp[MX];
    dp[0] = 1; dp[1] = 0; dp[2] = 0;

    loop(i,3,s+1)
    {
        dp[i] = 0;
        loop(j,3,i+1)
        {
            dp[i] = (dp[i] + dp[i - j]) % MOD;
        }
    }

    cout<<dp[s]<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


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

int main() {
  string s;
  cin >> s;

  int a_pos=-1, z_pos;
  for(int i=0; i<s.size(); i++) {
    if(a_pos==-1 && s.at(i)=='A') a_pos = i;
    if(s.at(i)=='Z') z_pos = i;
  }

  cout << z_pos-a_pos+1 << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	ll a,b;
    double c;
    
    cin >> a;
    cin >> c;
    
    b = (c*100+.5);
    
    ll res = (a*b);
    res/=100;
    
    cout << res; 
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

int main()
{
    

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k;
    }
    else if(k<=a+b) cout<<a;
    else cout<<a-(k-a-b);
    
    return 0;
}



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

typedef pair<int, int> P;
typedef pair<P, int> Pi;
const int N = (int)1e5 + 50;

int r, c;
int n;
vector<Pi> pts;
int in[N];

int on_bound(int x, int y) {
    return x == 0 || x == r || y == 0 || y == c;
}

int bound(int x, int y) {
    if(x == 0 && y == 0) return 0;
    if(x == 0 && 0 < y && y < c) return 1;
    if(x == 0 && y == c) return 2;
    if(0 < x && x < r && y == c) return 3;
    if(x == r && y == c) return 4;
    if(x == r && 0 < y && y < c) return 5;
    if(x == r && y == 0) return 6;
    if(0 < x && x < r && y == 0) return 7;

//    cout << x << " " << y << endl;
    assert(false);
}

bool cmp(P p1, P p2) {
    int b1 = bound(p1.first, p1.second), b2 = bound(p2.first, p2.second);
    if(b1 != b2) return b1 < b2;
    if(b1 == 1) return p1.second < p2.second;
    if(b1 == 3) return p1.first < p2.first;
    if(b1 == 5) return p1.second > p2.second;
    if(b1 == 7) return p1.first > p2.first;
}

int main() {
    cin >> r >> c >> n;
    for(int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(on_bound(x1, y1) && on_bound(x2, y2)) {
            pts.push_back({{x1, y1}, i});
            pts.push_back({{x2, y2}, i});
        }
    }
    sort(pts.begin(), pts.end(), [](const Pi &p1, const Pi &p2) {
        return cmp(p1.first, p2.first);
    });
    stack<int> S;

    for(const auto &p : pts) {
        int cur = p.second;
        if(in[cur]) {
            if(!S.empty() && S.top() == cur) {
                S.pop();
                in[cur] = false;
            }
            else {
                return cout << "NO" << endl, 0;
            }
        } else {
            in[cur] = true;
            S.push(cur);
        }
    }
    return cout << "YES" << endl, 0;

}

Measured memory_bytes: 4980
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=205;

int n,ans,now;
int a[N],k[N],vis[N],sg[N];

int solve(int n,int m){
	if (n<m) return 0;
	if (n%m==0) return n/m;
	return solve(n-((n%m-1)/(n/m+1)+1)*(n/m+1),m);
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d%d",&a[i],&k[i]);
		ans^=solve(a[i],k[i]);
	}
	if (ans) printf("Takahashi\n");
	else printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;

signed main(){
    int N,T,c,t;
    int Ans=114514;
    cin >>  N >> T;
    REP(i,N){
        cin >> c >> t;
        if(t<=T){
            Ans=min(Ans,c);
        }
    }
    if(Ans==114514){
        cout << "TLE" << endl;
    }else{
        cout << Ans << endl;
    }
    return 0;
}   


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  vector<vector <int> > a(n,vector<int> (m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<m;j++){
      sum+=a[i][j]*b[j];
    }
    sum+=c;
    if(sum>0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int n,a,b,p[5005];
ll dp[5005][5005];

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		p[x]=i;
	}
	memset(dp,0x20,sizeof dp);
	dp[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=0;j<i;++j)
			if(p[i]>p[j]){
				dp[i][i]=min(dp[i][i],dp[i-1][j]);
				dp[i][j]=min(dp[i][j],dp[i-1][j]+b);
			}
			else dp[i][j]=min(dp[i][j],dp[i-1][j]+a);
	cout<<*min_element(dp[n],dp[n]+n+1);
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  int val[5] = {};
  for(int i=0;i<n;i++){
  	string s;cin>>s;char c=s[0];
    switch(c){
      case ('M'): val[0]++;break;
      case ('A'): val[1]++;break;
      case ('R'): val[2]++;break;
      case ('C'): val[3]++;break;
      case ('H'): val[4]++;break;
      default: break;
    }
  }
  ll ans=0;
  for(int i=0;i<(1<<5);i++){
    ll tmp=1;int bit_count=0;
  	for(int j=0;j<5;j++){
      if((i>>j&1)!=1)continue;
      bit_count++;tmp*=val[j];
    }
    if(bit_count==3)ans+=tmp;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	string s;cin>>s;
	int n = s.length();
	if(s[n-1]=='s'){
		for(int i=0;i<n;i++){
			cout<<s[i];
		}
		cout<<'e'<<'s'<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			cout<<s[i];
		}
		cout<<'s'<<endl;
	}
}

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

import sys

r, c = map(int, sys.stdin.readline().split())
matrix = list()

for i in range(r):
    _line = list(map(int, sys.stdin.readline().split()))
    _line.append(sum(_line))
    matrix.append(_line)

_line = list()
for col in range(c+1):  # include sum column
    val = 0
    for row in range(r):
        val += matrix[row][col]
    _line.append(val)

matrix.append(_line)
for _line in matrix:
    str_x = list(map(str, _line))
    print(' '.join(str_x))



Measured memory_bytes: 5716