akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
 
int main() {
	int N;
	cin >> N;
	int A, B;
	cin >> A >> B;
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < N; i++) {
		int P;
		cin >> P;
		if (P <= A) x++;
		else if (P <= B) y++;
		else z++;
	}
	cout << min(x, min(y, z)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n; cin >> n;
    map<int,int> m;
    REP(i,n) {
        int a; cin >> a;
        m[a]++;
    }
    int ans = 0;
    bool ok = true;
    if (n % 2 == 0) {
        for(auto i = 1; i < n; i += 2) {
            if (m[i] != 2) {
                ok = false;
                break;
            }
        }
    } else {
        for(auto i = 0; i < n; i += 2) {
            if (i == 0) {
                if (m[i] != 1) {
                    ok = false;
                    break;
                }
            } else if (m[i] != 2) {
                ok = false;
                break;
            }
        }
    }
    if (ok) ans = modpow(2,n/2); 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3200
#include<cstdio>
int main(){
int x,y;
for(;;){
    std::scanf("%d%d",&x,&y);
    if(x == 0 && y == 0){
        break;
    }
    else if(x < y){
        std::printf("%d %d\n", x, y);
    }
        else {
            std::printf("%d %d\n", y, x);
        }
    }
}


Measured memory_bytes: 2740
import sys
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    ans = INF

    for r in range(H):
        for comb in combinations(range(1, H), r):
            sep = [0]
            sep.extend(list(comb))
            sep.append(H)

            res = r
            A = [0] * (r + 1)

            for j in range(W):
                B = [0] * (r + 1)
                for k in range(r + 1):
                    for i in range(sep[k], sep[k + 1]):
                        if S[i][j] == '1':
                            B[k] += 1

                ok = True
                divided = False
                for k in range(r + 1):
                    if B[k] > K:
                        ok = False
                        break
                    if A[k] + B[k] > K:
                        divided = True
                        break
                    else:
                        A[k] += B[k]

                if not ok:
                    res = INF
                    break
                if divided:
                    A = B
                    res += 1

            if ans > res:
                ans = res

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74572
s = gets.chomp
K = gets.to_i
N = s.to_s.size

dp = Array.new(105) {Array.new(4) {Array.new(2, 0)}} #動的計画法

dp[0][0][0] = 1

(0...N).each do |i|                            #それぞれの桁の数について 
    (0..K).each do |j|
        (0..1).each do |k|
            nd = s[i].to_i
            (0..9).each do |d|
                ni = i + 1
                nj = d == 0 ? j : j + 1        # 0以外の数字が出てきた回数
                nk = k == 0 && nd == d ? 0 : 1
                
                next if nj > K
                next if k == 0 && nd < d
                next if dp[i][j][k] == 0

                dp[ni][nj][nk] += dp[i][j][k]
            end
        end
    end
end

puts dp[N][K][0] + dp[N][K][1] 

Measured memory_bytes: 3836
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
import std.math;
 
auto solve(string s_)
{
    immutable N = s_.to!int();
    auto AS = new int[N];
    foreach(ref a;AS) a=readln.chomp().to!int();
    int[2][int] c;
    foreach(i;0..N)
    {
        immutable v=AS[i];
        if(v !in c) c[v]=[0,0];
        c[v][i&1]++;
    }
    immutable bs = sort(AS.dup).array();
    foreach(i;0..N)
    {
        immutable v=bs[i];
        if(v !in c) c[v]=[0,0];
        c[v][i&1]--;
    }
    int p=0;
    foreach(ref a;c) p+=(abs(a[0])+abs(a[1]))/2;
    return (p+1)/2;
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 5628
def ok(s):
    return s == s[::-1]

def solve(s):
    n = len(s)
    t = s[:n//2]
    u = s[::-1][:n//2]
    return "Yes" if (ok(s) and ok(t) and ok(u)) else "No"

assert solve("akasaka") == "Yes"
assert solve("level") == "No"
assert solve("atcoder") == "No"

s = input()
print(solve(s))

Measured memory_bytes: 3064
from math import *

def aaa(n):
  return int((sqrt(8*n+1)-1)/2)

def bk(n):
  if n <= 1:
    return {}
  r = {}
  for i in range(2, ceil(sqrt(n))+1):
    if n % i != 0:
      continue
    r.setdefault(i,0)
    while n % i == 0:
      n //= i
      r[i] += 1
    if n == 1:
      return r
  r.setdefault(n, 1)
  return r

n = int(input())
f = bk(n)
print(sum((aaa(m) for m in f.values())))

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1e9+7;

int main() {
    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    ll dx=tx-sx,dy=ty-sy;
    string ans;
    rep(i,dy) ans.push_back('U');
    rep(i,dx) ans.push_back('R');
    rep(i,dy) ans.push_back('D');
    rep(i,dx) ans.push_back('L');
    ans.push_back('L');
    rep(i,dy+1) ans.push_back('U');
    rep(i,dx+1) ans.push_back('R');
    ans.push_back('D');
    ans.push_back('R');
    rep(i,dy+1) ans.push_back('D');
    rep(i,dx+1) ans.push_back('L');
    ans.push_back('U');

    cout << ans << endl;
}
    

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

vector<int>adj[8];
bool marked[8];
int n=8,m=28;
int dfs(int s,int c)
{
	marked[s]=true;
	//for(int i=0;i<n;i++)
	//	cout<<marked[i]<<" ";
	//cout<<"\n";
	//cout<<"Vertex "<<s<<" ";
	//cout<<"\n";
	if(c+1==n){
	//	cout<<"\n";
		return 1;
	}
	int sum=0;
	for(auto x : adj[s])
	{
		if(!marked[x]){
			sum += dfs(x,c+1);
		
		marked[x]=false;}
	}
	
	return sum;

}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i=0;i<n;i++)
		marked[i]=false;
	cout<<dfs(0,0)<<"\n";
}

Measured memory_bytes: 3556
import java.util.*;
public class Main
{
    static int mod; static long[] fac;
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        mod = 998244353;
        int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); long ans = 0; fac = new long [n+1];
        fac[0] = 1;
        for (int i = 1; i <= n; i++) {
            fac[i] = (fac[i - 1]  * i) % mod;
        }
        for (int a = n - k; a <= n; a++) {
            long temp = (exponentiation(m - 1, a - 1) * nck(n - 1, a - 1))%mod;
            ans = (ans + (m * temp) % mod)%mod;
        }
        System.out.println(ans);
    }

    static long exponentiation(long base, long exp)
    {
        long t = 1L;
        while (exp > 0) {

            // for cases where exponent
            // is not an even value
            if (exp % 2 != 0)
                t = (t * base) % mod;

            base = (base * base) % mod;
            exp /= 2;
        }
        return t % mod;
    }

    static long nck(int n, int k) {
        if (n < k)
            return 0;
        long den = inv((int) (fac[k] * fac[n - k] % mod));
        return fac[n] * den % mod;
    }

    static int pow(long b, int e) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1)
                ans = ans * b % mod;
            e >>= 1;
            b = b * b % mod;
        }
        return (int) ans;
    }

    static int inv(int x) {
        return pow(x, mod - 2);
    }


}

Measured memory_bytes: 37464
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する
vector<vector<int> > G;
int V;
vector<int> color;

bool dfs(int v,int c){
    color[v] = c;
    for(int i = 0;i < G[v].size(); i++){
        if(color[G[v][i]] == c) return false;
        if(color[G[v][i]] == 0 && !dfs(G[v][i],-c)) return false;
    }
    return true;
}


int main() {
    ll n,m;
    cin >> n >> m;
    G = vector<vector<int> >(n+1);
    color = vector<int>(n+1,0);
    V = n + 1;
    REP(i,0,m){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1; i < color.size(); i++){
        if(color[i] == 0){
            if(!dfs(i,1)){
                cout << n * (n - 1) / 2 - m << endl;
                return 0;
            }
        }
    }
    ll a,b;
    a = b = 0;
    REP(i,0,V){
        if(color[i] == 1) a++;
        if(color[i] == -1) b++;
    }
    cout << a * b - m << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
int main() {
  long n;
  cin >> n;
  string ans = "";
  if (n == 0) {
    cout << "0" << endl;
    return 0;
  }
  while (n != 0){
    if (n % 2 == 0) {
      ans = ans + "0";
    } else {
      ans = ans + "1";
      n = n - 1;
    }
    n = n / (-2);
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++){
    cout << ans[i];
  }
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}

Measured memory_bytes: 256
s = input()


for i in s:
    if(i=='R'):
        mxcount=1
        break
    
else:
    mxcount = 0
count =1

if(len(s)>1): 
    for i in range(1,len(s)):
        if(s[i-1]=='R' and s[i]=='R'):
            count+=1
            if(mxcount<count):mxcount=count
            
        else:
            count=1
            
    print(mxcount)
    
else:
    if(s=='R'):
        print(1)
        
    else:print(0)

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define lol long long
#define mp(x,y) make_pair(x,y)
using namespace std;

// const lol mod=1e9+7;

/*  author: H3XoRuSH  */

vector<lol> adj[100011];
vector<lol> vis(100011,false);
vector<lol> dp(100011,0);

lol solve(lol a){
    vis[a]=true;
    lol temp=dp[a];
    for(lol i=0; i<adj[a].size(); i++){
        lol cur=adj[a][i];
        if(vis[cur]==false){
            temp=max(temp,1+solve(cur));
        }
        else temp=max(temp,1+dp[cur]);
    }
    dp[a]=temp;
    return dp[a];
}

int main() {
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lol n,m,a,b;
    cin >> n >> m;
    for(lol i=0; i<m; i++){
        cin >> a >> b;
        a--; b--;
        adj[b].push_back(a);
    }
    lol ans=0;
    for(lol i=0; i<n; i++){
        if(vis[i]==false) lol temp=solve(i);
        //cout << i+1 << ": " << dp[i] << endl;
        ans=max(ans,dp[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    int Q;
    cin >> Q;
    int N = 100001;
    vector<int> a(N,0);
    vector<bool> b(N,true);
    vector<int> s(N+1,0);
    
    b[0] = false;
    b[1] = false;

    rep(i,2,N) {
        if (b[i]){
            for(int j=i*2; j<N; j+=i){
                b[j] = false;
            }
        }
    }

    rep(i,0,N) {
        if (b[i]&&b[(i+1)/2]) {
            a[i]=1;
        }
    }
    rep(i,0,N) {
        s[i+1] = s[i] + a[i];
    }

    int ans[Q];
    int l,r;
    rep(i,0,Q) {
        cin >> l >> r;
        ans[i] = s[r+1]-s[l];
    }
    rep(i,0,Q) {
        cout << ans[i] << endl;
    }
 }



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

typedef struct d {
  struct d *parent;
  struct d *left;
  struct d *right;
  int key;
} node;
typedef node * Node;

 Node root;

void insert(int key){
  Node x = root;
  Node y = NULL;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = key;
  z->left = NULL;
  z->right = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NULL){
    root = z;
  }
  else if (z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorderTreeWalk(Node x){
  if(x != NULL){
    inorderTreeWalk(x->left);
    printf(" %d",x->key);
    inorderTreeWalk(x->right);
  }
}

void preorderTreeWalk(Node x){
  if(x == NULL){
    return;
  }
  printf(" %d",x->key);
  preorderTreeWalk(x->left);
  preorderTreeWalk(x->right);
}

void printer(){
  inorderTreeWalk(root);
  printf("\n");
  preorderTreeWalk(root);
  printf("\n");
}

int main(){
  int i, n, key;
  char command[10];

  scanf("%d ",&n);
  for(i=0; i<n; i++){
    scanf("%s ",command);
    if(!strcmp(command, "insert")){
      scanf("%d ",&key);
      insert(key);
    }
    else if(!strcmp(command, "print")){
      printer();
    }
  }

  return 0;
}



Measured memory_bytes: 25128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N, M;
int a1[200000], a2[200000];
int f[200000];

int main() {
	cin >> N >> M;
	rep(i, M){ cin >> a1[i] >> a2[i]; a1[i]--; a2[i]--; }
	rep(i, N){
		f[i] = 0;
	}
	rep(i, M){
		if(a1[i] == N-1){ f[a2[i]] = 1;}
		if(a2[i] == N-1){ f[a1[i]] = 1;}
	}
	int flg = 0;
	rep(i, M){
		if(a1[i] == 0 && f[a2[i]] == 1){ flg = 1;}
		if(a2[i] == 0 && f[a1[i]] == 1){ flg = 1;}
	}

	cout << (flg == 1 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, h, t, s= 0;

    cin>> n>> h;

    for(int i=0; i<n; i++)
    {
        cin>> t;

        if(t>= h)
            s++;
    }

    cout << s;
    nl;


    return 0;
}




Measured memory_bytes: 3660
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int ki=0;
		int gu=0;
		int sum=0;
		int[] ten=new int[N];
		for(int i=0; i<N; i++) {
			ten[i]=sc.nextInt();
			sum+=ten[i];
			if(ten[i]%2==1) {
				ki++;
			}
			else {
				gu++;
			}
		}
		if(ki>0 && gu>0) {
			int[] Kiten=new int[ki];
			int[] Guten=new int[gu];

			ki=0; gu=0;

			for(int i=0; i<N; i++) {
				if(ten[i]%2==0) {
					Guten[gu]=ten[i];
					gu++;
				}
				else if(ten[i]%2==1) {
					Kiten[ki]=ten[i];
					ki++;
				}
			}

			Arrays.sort(Kiten);
			Arrays.sort(Guten);
			if(ki%2==0) {
				System.out.println(sum-Kiten[0]);
			}
			else if(ki%2==1) {
				System.out.println(sum);
			}
		}
		else if(ki==0) {
			System.out.println(0);
		}
		else if(gu==0) {
			Arrays.sort(ten);

			int wa=0;
			for(int i=0; i<N; i++) {
				wa+=ten[i];
			}
			if(N%2==1) {
				System.out.println(wa);
			}
			else {
				System.out.println(wa-ten[0]);
			}
		}
	}
}

Measured memory_bytes: 23892
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(N):
    A[i] = A[i]*(-1)
import heapq
heapq.heapify(A)
for i in range(M):
    X = heapq.heappop(A)
    X = (-1*X)//2
    heapq.heappush(A, -1*X)

print(sum(A)*(-1))


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

		String S = sc.next();
		S = S + "a";
		long[][] num = new long[S.length()-1][S.length()+1];
		long answer = 0;
		for( int i=0; i<S.length()-1; i++ ){
			for( int j=i+1; j<S.length(); j++ ){
				String ss = S.substring(i,j);
				num[i][j] = Long.parseLong(ss);
				long a=2,b=2;
				if( i==0 || i==1 ){
					a = 1;
				}else{
					for( int m=0; m<i-2; m++ ){
						a=2*a;
					}
				}
				if( j==S.length()-2 || j==S.length()-1 ){
					b = 1;                  
                }else{                  
					for( int m=0; m<S.length()-j-3; m++ ){
						b=2*b;
					}
                }	                  
				num[i][j] *= a*b;
				answer += num[i][j];
			}
		}
		System.out.println( answer );
	}
}


Measured memory_bytes: 21716
import sys
n = int(sys.stdin.readline())
arr = [list(map(int, sys.stdin.readline().split())) for i in range(n)]

dp = [[-1] * 3 for i in range(n)]

dp[0][0] = arr[0][0]
dp[0][1] = arr[0][1]
dp[0][2] = arr[0][2]

for i in range(1, n):
	dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0])
	dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1])
	dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2])

print(max(dp[n - 1]))


Measured memory_bytes: 70236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vl v(5);
	int k=0;
	bool ans=true;
	rep(i,5)cin>>v[i];
	cin>>k;
	ans&=(v[4]-v[0]<=k);
	cout<<(ans?"Yay!":":(")<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long
char s[10005];
signed main(){
    int t; scanf("%lld",&t);
    scanf("%s",s);
    int k=strlen(s);
    if(k<=t) printf("%s\n",s);
    else {
        for(int i=0;i<t;i++) printf("%c",s[i]);
        printf("...\n");
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

vector<vector<pair<int, int>>> memo(16, vector<pair<int, int>>(0));

int num(ll a){
  int sum = 0;
  for (int i = 0; i < 16; i++){
    sum += (a >> i) & 0x01;
  }

  return sum;
}

int ok(ll bit){
  for (int i = 0; i < 16; i++){
    if ((bit >> i) & 0x01){
      for (int j = 0; j < memo[i].size(); j++){
        if (((bit >> memo[i][j].first) & 0x01) != memo[i][j].second){
          return 0;
        }
          cerr << bit << " " << i << " " << j << " " << ((bit >> memo[i][j].first) & 0x01) << " " << memo[i][j].second << endl;
      }
    }
  }

  return 1;
}

int main(void){
  int n;

  cin >> n;

  int a, x, y;

  for (int i = 0; i < n; i++){
    cin >> a;
    for (int j = 0; j < a; j++){
      cin >> x >> y;
      memo[i].push_back(pair<int, int>(x - 1, y));
    }
  }

  int m = 0;
  ll bit = 1;

  while (bit < pow(2, n)){
    if (ok(bit)){
//      cout << bit << endl;
      m = max(m, num(bit));
    }

    bit++;
  }


  cout << m << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
#define REP(i,n) for (int i = 1; i<= (n); i++)
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
const long double PI = acos(-1);
using ll = long long;
using ld = long double;
using namespace std;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;
    return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**12):
    if i**2 > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Measured memory_bytes: 2940
#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 a, b, c, k;
    cin >> a >> b >> c >> k;

    rep (i, k)
        if (a >= b)
            b *= 2;
        else if (b >= c)
            c *= 2;

    cout << (a < b && b < c ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3632
N, M, K=map(int, input().split())

#友達候補：　ブロック関係にない　友達ではない　間接的に友達
#友達候補＝友達の輪　ー　友達
#ブロックリストが友達の輪とsamegroupだったら−１

class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]
  
uni=UnionFind(N)
friends=[[] for _ in range(N)]
blocks=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int, input().split())
  friends[a-1].append(b-1)
  friends[b-1].append(a-1)
  uni.Unite(a-1,b-1)
for i in range(K):
  c,d=map(int, input().split())
  blocks[c-1].append(d-1)
  blocks[d-1].append(c-1)
  
for i in range(N):
  ans=uni.Count(i)-len(friends[i])-1
  for j in blocks[i]:
    if uni.isSameGroup(i,j):
      ans-=1
  print(ans, end=" ")

Measured memory_bytes: 42224
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int N, a, b, deg[100009]; vector<int> g[100009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 1; i < N; i++) {
		cin >> a >> b; a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	queue<int> que;
	for (int i = 0; i < N; i++) {
		if (deg[i] == 1) que.push(i);
	}
	int cur = N;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		if (deg[u] != 1) continue;
		for (int i : g[u]) {
			if (deg[i] >= 1) {
				deg[i] = deg[u] = 0;
				for (int j : g[i]) {
					if (deg[j] >= 1) deg[j]--;
					if (deg[j] == 1) que.push(j);
				}
			}
		}
		cur -= 2;
	}
	cout << (cur ? "First" : "Second") << '\n';
	return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(a<b&&b>(a+w)){
		cout<<abs(b-(a+w));
	}
	else if(a>b){
		cout<<abs(a-(b+w));
	}
	else if(a<=b<=(a+w)){
		cout<<"0";
	}
}

Measured memory_bytes: 256
use proconio::input;
use std::cmp::{max, min};

#[proconio::fastout]
fn main() {
    input! {
        ab: [i64; 2],
        cd: [i64; 2]
    }

    let mut ans = ab[0] * cd[0];

    for a in &ab {
        for c in &cd {
            ans = max(ans, a * c)
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

ll n = 1e5+10,m = 2e5+10;
ll INF = INT_MAX;
vector<ll> place(n,INF);
// bool ok = true;
vector<vector<Pll>> graph(n);
// template<class T>
bool dfs(int now, int pre = -1){
    bool ok = true;
    // is_move[now] = 1;
    for(auto i : graph[now]){
        int to = i.first;
        ll dis = i.second;
        if(to == pre)continue;
        if(place[to] == INF){
            place[to] = place[now] + dis;
            ok &= dfs(to, now);
        }
        else{
            if(place[to] != place[now] + dis){
                ok = false;
                break;
            }
        }
    }
    return ok;
}

int main(){
    cin >> n >> m;
    // vector<ll> l(m), r(m), d(m);
    // vector<vector<Pll>> graph(n);
    set<ll> st;
    rep(i,m){
        ll l,r,d;cin >> l >> r >> d;
        l--;r--;
        st.insert(l);
        st.insert(r);
        graph[l].emplace_back(Pll(r,d));
        graph[r].emplace_back(Pll(l,-d));
    }
    bool res = true;

    // clock_t start = clock();

    for(auto i : st){
        // if(graph[i].size() == 0)continue;
        // print(i,is_move[i],place[i]);
        if(place[i] == INF){
            place[i] = 0;
            res &= dfs(i);
        }
        if(!res)break;
    }

    // clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // printf("time %lf[ms]\n", time);
    cout << (res ? "Yes" : "No") << endl;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC\n";
    else
        cout << "ABC\n";
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  vvi A(N,vi(M));
  rep(i,N) {
    rep(j,M) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int ans = INF;
  vi except(M,0);
  while(1) {
    vi cnt(M,0);
    bool ok = true;
    rep(i,N) {
      int idx=0;
      rep(j,M) {
        if(except[A[i][j]]) {
          idx++;
        } else {
          break;
        }
      }
      if(idx==M) {
        cout << ans << endl;
        return 0;
      }
      cnt[A[i][idx]]++;
    }
    int n = 0;
    rep(i,M) {
      n = max(n,cnt[i]);
    }
    ans = min(ans,n);
    rep(i,M) {
      if(cnt[i]==n) {
        except[i]++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
MOD = (10 ** 9) + 7  # operować sobie na typie int32_t


def 関数(l,r,d):
    res = 0
    for i in range(l, r+1):
        if i % d == 0:
            res += 1
    return res

def çözmek():
    L, R, d = iimr()
    res = []
    res.append(関数(L, R, d))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mxN = 2e5 + 5;
const int INF = 1e9 + 7;

string s;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	if (s[s.size() - 1] == 's')
	{
		s += "es";
		cout << s;
	}
	else
	{
		s += 's';
		cout << s;
	}
	return 0;
}
//19-09-2020 17:31:58

Measured memory_bytes: 3660
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

[<EntryPoint>]
let main _ =
    let n = stdin.ReadLine() |> int64
    seq { 0L..n }
    |> Seq.map (fun x -> x * x )
    |> Seq.takeWhile ((>=) n)
    |> Seq.last
    |> printfn "%d"
    0

Measured memory_bytes: 12240
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
#include <queue>
#include <functional>

using namespace std;
typedef long long int ll;

int main(){

    string S;
    cin >> S;
    vector<pair<char, ll > > SS;
    char tmp = 'a';
    for(ll i = 0; i < 26; i++){
        SS.push_back(make_pair(tmp + i, 0));
    }

    for(ll i = 0; i < S.length(); i++){
        SS[S[i] - 97].second = -1;
    }

    //何が使えるか
    priority_queue<char, vector<char>, greater<char > > que;
    for(ll i = 0; i < SS.size(); i++){
        if(SS[i].second != -1) {
            que.push(SS[i].first);
        }
    }

    //26文字以下なら使っていないやつの中で最小を取り出せば良い
    if(S.length() < 26){
        cout << S << que.top() << endl;
        return 0;
    }

    //
    ll j = S.length()-1;
    bool flg = false;
    while(j > 0){
        //降順
        if(S[j-1] > S[j]){
            que.push(S[j]);
            //cout << S[j] << endl;
        }else{
            flg = true;
            que.push(S[j]);
            break;
        }
        j--;
    }

    if(flg == false){
        cout << "-1" << endl;
    }else{
        for(ll i = 0; i < j - 1; i++){
            //cout << i << endl;
            cout << S[i];
        }
        //cout << S[j];
        while(!que.empty()){
            if((S[j - 1] >  que.top())){
                //cout << que.top() << endl;
                que.pop();
            }else{
                break;
            }
        }
        cout << que.top() << endl;
    }

} 

Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut a: Vec<Vec<i64>> = vec![];

    for i in 0..n {
        let d: Vec<i64> = readnc();
        a.push(d);
    }

    let mut isok = true;
    let mut dec = 0;
    for i in 0..n {
        for j in 0..n {
            let mut required = true;
            for k in 0..n {
                if i == j || j == k || i == k {
                    continue
                }
                if a[i][j] > a[i][k] + a[k][j] {
                    isok = false;
                } else if a[i][j] == a[i][k] + a[k][j] {
                    required = false;
                }
            }
            if !required {
                dec += a[i][j];
            }
        }
    }

    let mut total = 0;
    for i in 0..n {
        for j in 0..n {
            total += a[i][j];

        }
    }

    if isok {
        println!("{}", (total-dec)/2);
    } else {
        println!("-1");
    }

}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define mkp make_pair
#define pb push_back
typedef long long ll;
int main()
{
	string s;
	cin>>s;
	if(s == "SUN")cout<<7<<endl;
	if(s == "MON")cout<<6<<endl;
	if(s == "TUE")cout<<5<<endl;
	if(s == "WED")cout<<4<<endl;
	if(s == "THU")cout<<3<<endl;
	if(s == "FRI")cout<<2<<endl;
	if(s == "SAT")cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val edges = Array.fill(n + 1)(new ArrayBuffer[(Int, Int)]())
  (1 until n).foreach { i =>
    val u, v, w = sc.nextInt
    edges(u) += ((v, w))
    edges(v) += ((u, w))
  }

  val result = new Array[Int](n + 1)

  def bfs(curs: List[(Int, Int, Int)]): Unit = {
    val nexts = curs.flatMap {case (pre, cur, w) =>
      result(cur) = w % 2
      edges(cur).collect{case (i, ww) if i != pre => (cur, i, (w + ww) % 2)}
    }
    if (nexts.nonEmpty) bfs(nexts)
  }

  bfs(List((0, 1, 0)))

  println(result.tail.mkString("\n"))
}

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

int main(){
    int h, w;
    cin >> h >> w;

    vector<vector<int>> a(h, vector<int>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> a[i][j];
        }
    }

    vector<vector<int>> ans;
    int count = 0;
    
    for(int x=0; x<h; x++){
        for(int y=0; y<w-1; y++){
            if(a[x][y] % 2 != 0){
                ans.push_back({x+1, y+1, x+1, y+2});
                count += 1;
                a[x][y] = 0;
                a[x][y+1] += 1;
            }
        }
    }
    for(int x=0; x<h-1; x++){
        if(a[x][w-1] % 2 != 0){
            ans.push_back({x+1, w, x+2, w});
            count += 1;
            a[x][w-1] = 0;
            a[x+1][w-1] += 1;
        }
    }

    cout << count << endl;
    for(int i=0; i<count; i++){
        cout << ans[i][0] << " " 
             << ans[i][1] << " " 
             << ans[i][2] << " " 
             << ans[i][3] << endl;
    }
    return 0;
}

Measured memory_bytes: 10032
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;


int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int ans = 0;
	if (X < Y) {
		ans = min((Y - X) * B + 2 * X * C, A * X + B * Y);
		ans = min(ans, 2 * Y * C);
	}
	else {
		ans = min((X - Y) * A + 2 * Y * C, A * X + B * Y);
		ans = min(ans, 2 * X*C);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
int main(void)
{
    char ch;
    while(1)
    {
        scanf("%c",&ch);
        if(ch == ' ')
        {
            printf(" ");
        }
        else
        {
            if(islower(ch)!= 0)
            {
                ch = toupper(ch);
            }
            else if(isupper(ch) != 0)
            {
                ch = tolower (ch);
            }
            printf("%c",ch);
        }

        if(ch == '\n') break;
    }
    return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

// STLの練習
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  int sum = accumulate(L.begin(), L.end(), 0);
  int Lmax = *max_element(L.begin(), L.end());
  if (sum - Lmax > Lmax)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

#define INF 1000*1000

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int b[n];
      int x[n];
      int y[n];
      for(int i=0;i<n;i++)
	cin>>b[i]>>x[i]>>y[i];

      double edge[n][n];
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  edge[i][j]=INF;

      for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	  {
	    //	    cout<<i<<" "<<j<<"  "<<
	    //  (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<<endl;
	    if((x[i]-x[j])*(x[i]-x[j])+
	       (y[i]-y[j])*(y[i]-y[j])<=2500)
	      {
		double tmp = sqrt((x[i]-x[j])*(x[i]-x[j])+
				 (y[i]-y[j])*(y[i]-y[j]));
		edge[i][j]=tmp;
		edge[j][i]=tmp;
		//cout<<"make_edge "<<i<<" "<<j<<endl;
	      }
	  }
      /*
      for(int i=0;i<n;i++,cout<<endl)
	for(int j=0;j<n;j++)
	  printf("%6.f ",edge[i][j]);
      */
      int m;
      cin>>m;
      for(int i=0;i<m;i++)
	{
	  int s,g;
	  cin>>s>>g;
	  //step,now,keiro
	  priority_queue<pair<double,pair<int,vector<int> > > >qu;
	  for(int i=0;i<n;i++)
	    if(b[i]==s)
	      qu.push(make_pair(0,make_pair(i,vector<int>())));

	  bool closed[n];
	  memset(closed,false,sizeof(closed));
	  vector<int> ans;
	  while(!qu.empty())
	    {
	      double step=-qu.top().first;
	      int now=qu.top().second.first;
	      vector<int> load=qu.top().second.second;
	      qu.pop();
	      load.push_back(b[now]);

	      //	      cout<<"step:"<<step<<" "<<now<<endl;
	      //for(int i=0;i<load.size();i++){cout<<load[i];if(i!=load.size()-1)cout<<" ";else cout<<endl;}


	      if(b[now]==g)
		{
		  ans=load;
		  break;
		}
	      if(closed[now])
		continue;
	      closed[now]=true;
	      for(int i=0;i<n;i++)
		{
		  if(edge[now][i]!=INF && !closed[i])
		    qu.push(make_pair(-(step+edge[now][i]),make_pair(i,load)));
		}
	    }
	  if(ans.empty())
	    cout<<"NA"<<endl;
	  else
	    {
	      for(int i=0;i<ans.size();i++)
		{
		  cout<<ans[i];
		  if(i!=ans.size()-1)
		    cout<<" ";
		  else
		    cout<<endl;
		}
	    }
	}
    }

}

Measured memory_bytes: 1304
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int int_pow(int n,int m){
	int ans = 1;
	while(m--) ans *= n;
	return ans;
}

int main(){
	while(true){
		vector<int> n[3];
		char C;
		int r;
		int cnt = 0;
		while(true){
			r = scanf("%c",&C);
			if(r==EOF) return 0;
			if(C=='\n') break;
			else if(C=='+' || C=='=') cnt++;
			else if(C=='X') n[cnt].push_back(-1);
			else n[cnt].push_back(C-'0');
		}
		bool na = true;
		for(int t=0;t<10;t++){
			int n_[3] = {};
			for(int i=0;i<3;i++){
				if(t==0 && n[i].size()>=2 && n[i][0]==-1) goto NEXT;
				for(int j=0;j<n[i].size();j++){
					int a = n[i][n[i].size()-j-1];
					if(a==-1) a = t;
					n_[i] += a*int_pow(10,j);
				}
			}
			if(n_[0]+n_[1]==n_[2]){
				printf("%d\n",t); na = false; break;
			}
			NEXT:;
		}
		if(na) puts("NA");
	}
}

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

int main(){
    int N,Y;
    cin >> N >> Y;
    int res10000 = -1,res5000 = -1, res1000 = -1;
    for(int a = 0;a <= N;++a){
        for(int b = 0;a + b <= N;++b){
            int c = N - a - b;
            int total = 10000 * a + 5000 * b + 1000 * c;
            if(total == Y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 256
X, Y = map(int,input().split())
MOD = 10 ** 9 + 7
if (X + Y) % 3 != 0 or 2 * X < Y or 2 * Y < X:
    print(0)
elif 2 * X == Y or 2 * Y == X:
    print(1)
else:
    turn = (X + Y) // 3
    turn2 = X - turn
    turn1 = turn - turn2
    ans = turn
    inv = [0, 1]
    for i in range(2, min(turn1, turn2) + 1):
        ans = ans * (turn - i + 1) % MOD
        ans = ans * (-inv[MOD % i] * (MOD // i)) % MOD
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    print(ans % MOD)

Measured memory_bytes: 16300
from bisect import bisect_left
from random import randint
D = int(input())
Cs = list(map(int, input().split()))
Sss = []
for _ in range(D):
    Ss = list(map(int, input().split()))
    Sss.append(Ss)

def change(d, afterIdx):
    global score
    i = d - 1
    beforeIdx = Ts[i] - 1
    afterIdx -= 1
    if beforeIdx == afterIdx:
        return

    newScore = score

    before = lasts[beforeIdx]
    # dが何番目にあるか
    k1 = bisect_left(before, d)
    w = before[k1+1] - d
    h = d - before[k1-1]
    newScore -= Sss[i][beforeIdx]
    newScore -= w * h * Cs[beforeIdx]

    after = lasts[afterIdx]
    # dが何番目にあるか
    k2 = bisect_left(after, d)
    w = after[k2] - d
    h = d - after[k2-1]
    newScore += Sss[i][afterIdx]
    newScore += w * h * Cs[afterIdx]

    if newScore > score:
        lasts[beforeIdx] = before[:k1] + before[k1+1:]
        lasts[afterIdx] = after[:k2] + [d] + after[k2:]
        Ts[i] = afterIdx + 1
        score = newScore

Ts = []
for _ in range(D):
    Ts.append(randint(1, 26))

score = 0
lasts = [[0] for _ in range(26)]
for i, t in enumerate(Ts):
    d = i + 1
    t -= 1
    score += Sss[i][t]
    lasts[t].append(d)
    for j in range(26):
        score -= (d - lasts[j][-1]) * Cs[j]

for i in range(26):
    lasts[i].append(D+1)


for i in range(100000):
    change(randint(1, D), randint(1, 26))

for t in Ts:
    print(t)


Measured memory_bytes: 83512
import string
n,k =[int(i) for i in input().split()]
not_use=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in not_use]

def check(n):
    for i in str(n):
        if(int(i) in not_use):
            return False
    return True


x=n-1
while True:
    x+=1
    if(check(x)==True):
        print(x)
        exit()

Measured memory_bytes: 3896
#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.at(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.at(i).at(j);
        }
    }
    int Count=0;
    for(int i=0; i<N;i++){
        int Sum=C;
        for(int j=0; j<M; j++){
            Sum+=A.at(i).at(j)*B.at(j);
        }
        if(Sum>0){
            Count ++;
        }

    }
    cout<<Count<<endl;
}

Measured memory_bytes: 256