akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            String str = sc.nextLine();
            if("0".equals(str)){
                break;
            }
            char[] c = str.toCharArray();
            int sum = 0;
            for (int i = 0; i < c.length; i++) {
                sum += c[i] - '0';
            }
            ln(sum);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 26760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n, k;
    cin >> n >> k;

    if (k > (n-1)*(n-2)/2) {
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int,int>> vp;
    rep(i, n-1) vp.push_back({1, i+2});

    int d = (n-1)*(n-2)/2 - k;
    if (d == 0){
        cout << vp.size() << endl;
        for(auto e : vp) cout << e.first << " " << e.second << endl;
        return 0;
    }

    for(int i=2;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            vp.push_back({i,j});
            d--;
            if (d == 0){
                cout << vp.size() << endl;
                for(auto e : vp) cout << e.first << " " << e.second << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3628
a = int(input())
x = list(map(int,input().split()))
ax = list(set(x))
x.sort()
ax = list(set(x))
def ch(l):
    # print(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]])
    for i, j ,k in zip(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]]):
        if j != i ^ k: break
    else:
        return(1)
    return(0)
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
if len(ax) < 3:
    if (sum(x) == 0) :
        print("Yes")
        exit()
    if (len(ax)) <2:
        print("No")
        exit()
    if x.count(0)*2 == x.count(ax[1]) and len(x) == x.count(0) + x.count(ax[1]):
        print("Yes")
        exit()
        
    print("No")
    exit()
t = (len(x) == x.count(ax[0]) + x.count(ax[1]) + x.count(ax[2])) * (x.count(ax[1]) == x.count(ax[0]) and x.count(ax[0]) == x.count(ax[2]))*ch(ax)

y(1,t)

Measured memory_bytes: 14212
#include<iostream>
#include<algorithm>
using namespace std;
long long s[1000009];
long long  b[1000090];
long long  const mod=1e9+7;
int   main(){

    long long  a;
    cin>>a;
    s[0]=0;
    for(long long  i=1;i<=a;i++){
     cin>>b[i];
     s[i]=s[i-1]+b[i];
     s[i]=s[i]%mod;
    }
    long long ans=0;
    for(long long  i=1;i<a;i++){
          ans=ans+b[i]*(s[a]-s[i]+mod)%mod;
          ans=ans%mod;
    }
    cout<<ans<<endl;
    system("pause");


}

Measured memory_bytes: 6252
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define INF 10000000000000000LL
#define ll  long long 
const int inf =INT_MAX;
const int MAX=3e5+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=1e6+9;
const int MAX_A=71;
const int LN=20;
using namespace std;
int main(){
    int n;
    cin>>n;
    map<int , int > mp;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        mp[a]++;
    }
    int even=0;
    int ans =0;
    for(auto x:mp){
        ans = ans+1;
        if(x.second%2==0)
            even = even+1;
    }
    if(even%2==1)
        ans = ans-1;
    cout<<ans;



}


Measured memory_bytes: 8092
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
ll M3 = 1e8;
ll MAX = 5001;
string s = "Everything correct till here!";

void show(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<v[i].ff<<" "<<v[i].ss<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;
    while(T--)
    {
        string s,t; cin>>s>>t;
        string ans = "";
        ll n = s.length();
        ll m = t.length();
        ll dp[n+1][m+1];
        f1(i,n) dp[i][0] = 0;
        f(i,m+1) dp[0][i] = 0;
        f1(i,n)
        {
            f1(j,m)
            {
                if(s[i-1] == t[j-1])
                    dp[i][j] = dp[i-1][j-1] + 1;
                else
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
        if(dp[n][m] == 0)
        {
            cout<<"";
            continue;
        }

        ll i = n, j = m;
        while(i>0 and j > 0)
        {
            if(dp[i][j] == dp[i][j-1])
                j--;
            else if(dp[i][j] == dp[i-1][j])
                i--;
            else
            {
                ans += s[i-1];
                i--;
                j--;
            }
        }
        reverse(all(ans));
        cout<<ans<<"\n";
        
    }
    return 0;
}



Measured memory_bytes: 70656
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;

	int a_idx = 0;
	int b_idx = 0;
	int idx_cnt = 0;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		// int N = Integer.parseInt(line);
		int a = Integer.parseInt(line.split("\\s+")[0]);
		int b = Integer.parseInt(line.split("\\s+")[1]);

		long res = lcm(a, b);
		System.out.println(res);
		return;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
	private long gcd(long a, long b) {
	    if (b == 0) return a;
	    else return gcd(b, a%b);
	}
	private long lcm(long a, long b) {
	    return (a / gcd(a, b) * b);
	}

}


Measured memory_bytes: 23892
import sys
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    def print(self):
        print('',' '.join(map(str, self.root.inwalk())))
        print('',' '.join(map(str, self.root.prewalk())))
    
class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None
    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret
    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret
tree = Tree()
n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    else:
        tree.print()

Measured memory_bytes: 265336
<?php
list($X, $Y) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

for ($i = 0; $i <= $X; $i ++) {
    if (2 * $i + 4 * ($X - $i) === $Y) {
        echo 'Yes';
        return;
    }
}

echo 'No';

Measured memory_bytes: 16168
// abc167_c
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

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;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m, x, ans = inf;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));

  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }

  rep(s, 1 << n) {
    int cost = 0;
    bool check = true;
    vector<int> d(m, 0);
    rep(i, n) {
      if (s >> i & 1) {
        cost += c.at(i);
        rep(j, m) d.at(j) += a.at(i).at(j);
      }
    }

    rep(j, m) if (d.at(j) < x) check = false;
    if (check)
      ans = min(ans, cost);
  }

  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
MOD = 10 ** 9 + 7
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
res = 0
for i in range(N - 1):
    cnt = 0
    _cnt = 0
    for j in range(i + 1, N):
        if A[i] < A[j]:
            cnt += 1
        elif A[i] > A[j]:
            _cnt += 1
    res += (cnt * (K - 1) * K // 2 + _cnt * K * (K + 1) // 2) % MOD
print(res % MOD)


Measured memory_bytes: 9196
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> ret;
  list<int> l;

  list<int>::iterator it = l.begin();

  int q,c,x,d;
  cin >> q;

  for(ii=0;ii<q;ii++){
    cin >> c;

    switch(c){

    case 0:

      cin >> x;
      it = l.insert(it,x);

      break;

    case 1:
      cin >> d;
      advance(it,d);
      break;

    case 2:
      it = l.erase(it);
      //it--;
      break;
    }
    
  }

  it = l.begin();
  while(it!=l.end()){
    cout << *it << endl;
    it++;
  }
  //for(auto a : l){
  //  cout << a << endl;
  //}
  return 0;
}



Measured memory_bytes: 18556
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
import itertools
import math
input = sys.stdin.readline

N = int(input())
list_P = tuple(map(int, input().split()))
list_Q = tuple(map(int, input().split()))

List_All = list(itertools.permutations(list(range(1, N+1))))
# print(List_All)
Pi = List_All.index(list_P)
Qi = List_All.index(list_Q)
print(abs(Pi-Qi))


Measured memory_bytes: 13872
#%%
n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]
count = [0] * n
tmp = [_ for _ in range(n)]
ans = 0

while len(tmp) >= 1:
    check = [0] * n
    t = []
    for i in tmp:
        if check[i] == 0 :
            j = a[i][count[i]]
            if i == a[j][count[j]] and check[j] == 0:
                count[i] += 1
                count[j] += 1
                check[i], check[j] = 1, 1
                if count[i] < n-1:
                    t.append(i)
                if count[j] < n-1:
                    t.append(j)
    tmp = t
    ans += 1

if count.count(n-1) == n:
    print(ans)
else:
    print(-1)
    

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

using namespace std;
int32_t  main(){
   int k;
   cin>>k;
    int start = 7, c=1;
    int ans = start%k;
    if(k%2==0||k%5==0){
       cout<<"-1";
       return 0;
    }else{
       while(ans!=0){
           ans = ans*10+7;
           c++;
           ans= ans%k;
       }
  cout<<c;

    }

    
   return 0;
}


// somenumber % 7 
 
// 7 % 3  1 

                   
// 1 2 3 4 5 6 7 8 9 10 11 12 13 

// 1 2 3 4 5 6 7 8 9 10 11 12 13 

// 1 2 3 4 5 6 7 8 9 10 11 12 13 


// 1 2 3 4 5 6 7 8 9 10 11 12 13 


// 1 2 3 4 5 6 7 8 9 10 11 12 13 



Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> left(N, 0), right(N, 0);
  for(int i = 1; i < N; i++) {
    left[i] = max(left[i - 1], A[i - 1]);
  }
  for(int i = N - 2; i >= 0; i--) {
    right[i] = max(right[i + 1], A[i + 1]);
  }

  for(int i = 0; i < N; i++) {
    cout << max(left[i], right[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 3968
N = int(input())
A = [int(input()) for _ in range(N)]
if any(a - b > 1for a, b in zip(A, [-1]+A)): print(-1)
else:
    ans = 0
    for a, nxt in zip(A, A[1:]+[0]):
        if a >= nxt:
            ans += a
    print(ans)

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

struct people{
  int par;
  LL d;
};

vector<struct people> uf;

int find(int a){
  if(a==uf[a].par) return uf[a].par;
  else{
    int b=find(uf[a].par);
    uf[a].d+=uf[uf[a].par].d;
    uf[a].par=b;
    return b;
  }
}

bool uni(int l,int r,int d){
  int lp=find(l);
  int rp=find(r);
  if(lp==rp){
    if(uf[r].d-uf[l].d==d) return true;
    else return false;
  }
  uf[rp].par=l;
  uf[rp].d+=d-uf[r].d;
  return true;
}

int main(){
  int n,m;
  cin >> n >> m;
  uf=vector<struct people>(n+1);
  for(int i=0;i<=n;i++) uf[i]={i,0};
  bool ans=true;
  int l,r,d;
  for(int i=0;i<m;i++){
    cin >> l >> r >> d;
    ans&=uni(l,r,d);
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,K;
  cin >>N >>K;
  if(N%K==0) cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 256
open System
let readNumPair () =
  let str = stdin.ReadLine ()
  let ints =
    str.Split [|' '|]
    |> Array.map (System.Int32.TryParse >> snd)
  ints.[0], ints.[1]

type Path = {
  id: int;
  cost: int;
  time: int;
}

let getPath id =
  let cost, time = readNumPair ()
  {id = id; cost = cost; time = time}

let pathAmt, timeLimit = readNumPair ()

let ans =
  let filtered =
    List.map getPath [1..pathAmt]
    |> List.filter (fun path -> path.time <= timeLimit)
  match filtered with
  | [] -> None
  | l -> List.minBy (fun path -> path.cost) l |> Some

match ans with
| None -> printfn "TLE"
| Some path -> printfn "%d" path.cost

Measured memory_bytes: 14172
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  int lmax = 0, rmin = 1e6;
  for (int i = 0; i < m; ++i)
  {
    int l, r;
    cin >> l >> r;
    lmax = max(lmax, l);
    rmin = min(rmin, r);
  }
  int ans = rmin - lmax + 1;
  if (ans < 0)
    ans = 0;
  cout << ans << endl;

  return 0;
}


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

typedef complex<double>Point;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point p;
    double r;
    Circle(const Point &p=Point(),double r=0.0):p(p),r(r){}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point>Polygon;

const double PI=acos(-1);
const double EPS=1e-8;
const double INF=1e16;

inline double square(double a){return a*a;}
inline double norm(const Point &a){return square(a.real())+square(a.imag());}
inline double dot(const Point &a,const Point &b){return (conj(a)*b).real();}
inline double cross(const Point &a,const Point &b){return (conj(a)*b).imag();}
inline double toDeg(double t){return t/PI*180.0;}
inline double toRad(double t){return t/180.0*t;}
#define equals(a,b) (fabs((a)-(b))<EPS)

bool isOrthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
    return isOrthogonal(s1.p1-s1.p2,s2.p1-s2.p2);
}

bool isParallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
    return isParallel(s1.p1-s1.p2,s2.p1-s2.p2);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

void getPoint(Point &p){
    double x,y;
    scanf("%lf%lf",&x,&y);
    p=Point(x,y);
}

int main(){
    Segment s;
    getPoint(s.p1);
    getPoint(s.p2);

    int q;
    scanf("%d",&q);

    while(q--){
        Point p;
        getPoint(p);
        Point x=project(s,p);
        printf("%.20lf %.20lf\n",x.real(),x.imag());
    }
    return 0;
}

Measured memory_bytes: 1256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            var x = cin.ReadInt;

            var result = 0;
            for (var i1 = 0; i1 <= a; i1++) {
                for (var i2 = 0; i2 <= b; i2++) {
                    for (var i3 = 0; i3 <= c; i3++) {
                        if (x == i1*500 + i2*100+ i3*50) {
                            result++;
                        }
                    }
                }
            }
            WriteLine(result);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <stdio.h>
int main(void)
{
	int n,i,a,b,A,B;
	while(1)
	{
		A = 0;
		B = 0;
		scanf("%d",&n);
		if(n == 0) return 0;
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&a,&b);
			if(a > b)
			{
				A += a+b;
			}
			else if(a < b)
			{
				B += a+b;
			}
			else
			{
				A += a;
				B += b;
			}
		}
		printf("%d %d\n",A,B);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int a, b, c, k; cin >> a >> b >> c >> k;
  	priority_queue<int> nums;
    nums.push(a);  nums.push(b);  nums.push(c);
  	while(k){
    	k--;
      	int max_num = nums.top();
      nums.pop();
      nums.push(max_num * 2);
    }
  
  int ans = 0;
  	while(!nums.empty()){
    	ans += nums.top();
      nums.pop();
    }
  cout << ans << endl;
    return 0;
}


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

const int N = 2e5+7;
int dp[N];

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

    int n;
    cin>>n;

    map<int, int> mp;
    vector<pair<int, int>> ranges;

    for (int i=1; i<=n; i++) {
        int x, d;
        cin>>x>>d;
        int l = x-d, r = x+d;
        mp[l] = mp[r] = 0;
        ranges.emplace_back(l, r);
    }

    int id = 0;
    for (auto & pr: mp) {
        pr.second = ++id;
    }

    sort(ranges.begin(), ranges.end());

    int ans = 0, done = 0;
    for (auto pr: ranges) {
        int l = mp[pr.first], r = mp[pr.second];
        while (done < l)    dp[done+1] = max(dp[done+1], dp[done]), done++;
        dp[r] = max(dp[r], dp[l]+1);
        ans = max(ans, dp[r]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11252
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	deque<string> r;
	r.push_back(s);

	bool f = true;

	string buf;
	for (int i = 0; i < q; i++)
	{
		int x;
		cin >> x;

		switch (x)
		{
			case 1:
				f = !f;
				break;

			case 2:
				int t;
				string c;
				cin >> t >> c;
				if (t == 1)
				{
					if (f)
					{
						r.push_front(c);
					}
					else
					{
						r.push_back(c);
					}
				}
				else
				{
					if (f)
					{
						r.push_back(c);
					}
					else
					{
						r.push_front(c);
					}
				}
				break;
		}
	}

	string res;
	for (string it : r)
	{
		res += it;
	}
	if (!f)
	{
		reverse(all(res));
	}
	println(res);
}


Measured memory_bytes: 12128
#include<stdio.h>
int main(void)
{
   int n, i;
   int h = 0;
   int max = 0;
   int sum = 0;

   scanf("%d", &n);

   for (i=0; i < n; i++)
   {
      scanf("%d", &h);
      if(max < h) max = h;
      if(h >= max) {
         sum++;
      }
      
   }
   printf("%d",sum);

   return 0;

   
}


Measured memory_bytes: 128
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
typedef long long ll;

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

    ll a[n + 1];
    for (ll i = 1; i < n + 1; i++) cin >> a[i];

    ll sumBall[n + 1];
    if (a[n] == 1) sumBall[n] = 1;
    else sumBall[n] = 0;

    for (ll i = 0; i < n; i++) sumBall[i] = 0;

    for (ll i = n - 1; i > 0; i--) {
        ll ball = 0;
        ll multiple = i;
        ll j = 1;
        while (multiple <= n) {
            // cout << "i = " << i << ", sumBall[i] = " << sumBall[i] << endl;
            ball += sumBall[multiple];
            ++j;
            multiple = i * j;
        }

        if (ball % 2 == a[i]) sumBall[i] = 0;
        else sumBall[i] = 1;
    }

    vector<int> res;
    for (ll i = 1; i <= n; i++) {
        if (sumBall[i] == 1) res.push_back(i);
    }

    cout << res.size() << endl;
    for (ll i = 0; i < res.size(); i++) cout << res[i] << endl;
}


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

using namespace std;

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

int main() {
  int N;
  vector<int> b;

  cin >> N;
  b.resize(N);
  REP(i,N) cin >> b[i];

  vector<int> res;
  while ((int)b.size() > 0) {
    bool f = false;
    for (int i = b.size() - 1; i >= 0; i--) {
      if (b[i] == i + 1) {
        b.erase(b.begin() + i);
        res.emplace_back(i + 1);
        f = true;
        break;
      }
    }
    if (!f) {
      cout << -1 << endl;
      return 0;
    }
  }

  reverse(res.begin(), res.end());
  REP(i,res.size()) cout << res[i] << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = list(map(int, input().split()))
acts = [(x, i) for i, x in enumerate(A)]
acts.sort()
dp = [[-1]*N for _ in range(N)]
 
def solve(l, r):
    if r < l:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    k = r - l
    act, init_pos = acts[k]
    gain_l = act * abs(l - init_pos)
    gain_r = act * abs(r - init_pos)
    res = dp[l][r] = max(gain_l + solve(l+1, r), gain_r + solve(l, r-1))
    return res
 
print(solve(0, N-1))

Measured memory_bytes: 137900
NumPri = int(input())
Triger = 0
while True:
  for i in range(2,NumPri):
    if NumPri%i == 0:
      NumPri += 1
      Triger += 1
      break
  if Triger == 1:
    Triger = 0
    continue
  print(NumPri)
  break

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define SZ(x) ((int)(x).size())
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())

const static llong MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static double eps = 1e-6;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int h, w;
char field[8][8];
bool visited[8][8];

void dfs(int i, int j) {
    visited[i][j] = true;
    if (i + 1 < h && visited[i + 1][j] != true && field[i + 1][j] == '#') dfs(i + 1, j);
    if (j + 1 < w && visited[i][j + 1] != true && field[i][j + 1] == '#') dfs(i, j + 1);
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    int cnt = 0;
    rep(i, h) {
        rep(j, w) {
            char a;
            cin >> a;
            if (a == '#') ++cnt;
        }
    }

    if (cnt == h + w - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

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

int main()
{
    long long n, k;
    scanf("%lld%lld", &n, &k);
    long long v[n];
    for(long long i = 0; i < n; i++)
        scanf("%lld", &v[i]);
    sort(v, v + n);
    long long i = n - 1;
    while(k > 0 && i >= 0)
    {
        v[i] = 0;
        k--;
        i--;
    }
    long long sum = 0;
    for(i = 0; i < n; i++)
        sum += v[i];
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>


int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if ( a < b && b < c) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll mod = 1000000007;
# define INF (1 << 29)
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

int dist[210][210];
void warshall_floyd(int n){
    for(int k=1; k<=n; k++){
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main(void){
    int n,m,r;
    cin >> n >> m >> r;
    vector<int> cities;
    for(int i=1; i<=r; i++){
        int x; cin >> x;
        cities.push_back(x);
    }

    // 初期化
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(i==j){
                dist[i][j] = 0;
            }
            else{
                dist[i][j] = INF;
            }
        }
    }

    // グラフの受け取り
    for(int i=1; i<=m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    // 全街の間の最短路がわかる
    warshall_floyd(n);

    // 答えを求めよう
    // 貪欲の反例を見つけたｧｧぁ
    ll ans = INF;

    // r個の並び全てについて距離を調べられる
    // next_permutation使う
    sort(cities.begin(), cities.end());
    do{
        ll tmp_ans = 0;
        for(int i=0; i<r-1; i++){
            tmp_ans += dist[cities[i]][cities[i+1]];
        }
        if(tmp_ans <= ans){
            ans = tmp_ans;
        }
    }while(next_permutation(cities.begin(), cities.end()));

    cout << ans;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String T = sc.next();
    String str = "";
    
    for (int i = 0; i < N; i++) {
      str += S.charAt(i);
      str += T.charAt(i);
    }
    System.out.print(str);
  }
}

Measured memory_bytes: 23892
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




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

	vll d(N);
	rep(i, N) cin >> d[i];
	sort(all(d));
	d.erase(unique(all(d)), d.end());
	cout << d.size() << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int t,n;
    cin >> t >> n;
    if(!t&&!n) return 0;
    deque<pair<int,pair<int,int> > > bfs;
    int steps[128][128];
    REP(i,128){
      REP(j,128){
	steps[i][j]=0;
      }
    }
    while(n--){
      int x,y;
      cin >> x >> y;
      steps[x+64][y+64]=-1;
    }
    int sx,sy;
    cin >> sx >> sy;
    for(bfs.PB(MP(t+1,MP(sx,sy)));SZ(bfs);bfs.pop_front()){
      pair<int,int> xy = bfs.front().second;
      int x = xy.first,y = xy.second;
      int tmpstep = bfs.front().first;
      if(steps[x+64][y+64]>=0)
	if(steps[x+64][y+64]<tmpstep){
	  steps[x+64][y+64]=tmpstep;
	  if(--tmpstep){
	    bfs.PB(MP(tmpstep,MP(x,y+1)));
	    bfs.PB(MP(tmpstep,MP(x+1,y)));
	    bfs.PB(MP(tmpstep,MP(x+1,y+1)));
	    bfs.PB(MP(tmpstep,MP(x,y-1)));
	    bfs.PB(MP(tmpstep,MP(x-1,y)));
	    bfs.PB(MP(tmpstep,MP(x-1,y-1)));
	  }
	}
    }
    int answer=0;
    REP(i,128){
      REP(j,128){
	if(steps[i][j]>0) answer++;
      }
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 1296
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int a;
  cin >> a;

  int max_v = 0;

  for(int i = 2; i < 32; i++){
    int tmp = i;
    if (tmp * i > a){
      tmp = i;
    }else{
      while(tmp <= a){
        tmp *= i;
      }
    }
    max_v = max(max_v, tmp/i);
  }

  cout << max_v <<endl;

  return 0;
}


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

using namespace std;
 
int main() {
  
  string s;
  cin >> s;
  
  int len = s.length();
  //int arr[len] = {};
  int sum = 0;
  for(int i = 0; i < len ; i++){
   //arr[i] = stoi(s.substr(i,1).c_str());
    sum += stoi(s.substr(i,1).c_str());
  }
  int i = stoi(s.c_str()) % sum;
  if(i == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;  
  }
}

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

int main()
{
    // 入力
    int N, M, Q;
    cin >> N >> M >> Q;

    // 二次元配列に列車の区間を保存、g[始都市][終都市]
    int g[N][N];
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            g[i][j] = 0;
        }
    }
    // L,R は1から始まるから1引く
    for(int i = 0; i < M; i++)
    {
        int L, R;
        cin >> L >> R;
        g[L-1][R-1] += 1;
    }

    // 質問
    int p[Q] = {0};
    int q[Q] = {0};
    for(int i = 0; i < Q; i++)
    {
        int a, b;
        cin >> a >> b;
        p[i] = a - 1;
        q[i] = b - 1;
    }

    // g配列を動的にカウント
    int g2[N][N];
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            g2[i][j] = 0;
        }
    }
    // g2[N-1][0]を初期化
    g2[N-1][0] = g[N-1][0];
    // 端から入れていく
    for(int i = N-2; i >= 0; i--)
    {
        g2[i][0] = g2[i+1][0] + g[i][0];
    }

    for(int i = 1; i < N; i++)
    {
        g2[N-1][i] = g2[N-1][i-1] + g[N-1][i];
    }

    // 中を入れていく
    for(int i = N-2; i >= 0; i--)
    {
        for(int j = 1; j < N; j++)
        {
            g2[i][j] = g[i][j] + g2[i+1][j] + g2[i][j-1] - g2[i+1][j-1];
        }
    }

    // 目的の区間にある列車の数を出力
    for(int i = 0; i < Q; i++)
    {
        cout << g2[p[i]][q[i]] << endl;
    }

    return 0;
}

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

using namespace std;

const int maxn = 2e5 + 5;

int a[maxn] , vis[maxn];
int ans , pos;
vector <int> v;

void dfs(int u) {
	ans++;
	vis[u] = ans;
	v.push_back(u);
	if(!vis[a[u]])dfs(a[u]);
	else {
		pos = vis[a[u]];
		v.push_back(a[u]);
		return;
	} 
}

int main() {
	int n ;
	long long k;
	ios::sync_with_stdio(0);
	cin >> n >> k;
	for(int i = 1 ; i <= n ; i++)cin >> a[i];
	dfs(1);
	if(k < v.size()) {
		cout << v[k] << "\n";
	}
	else {
		k -= v.size();
		int len = v.size() - pos;
		cout << v[pos +  k % len] << "\n"; 
	}
	return 0;
}

Measured memory_bytes: 11640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int x = Integer.parseInt(str[1]);
		int y = Integer.parseInt(str[2]);

		int dist[] = new int[n - 1];

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (i == j || i > j)
					continue;

				int d = Math.min(Math.abs(i - j), Math.abs(y - j) + Math.abs(i - x) + 1);
				dist[d - 1]++;
			}
		}

		for (int i = 0; i < n - 1; i++) {
			System.out.println(dist[i]);
		}
	}
}

Measured memory_bytes: 33732
N, = map(int, input().split())
M=10**9+7
n=N
_ALL=1<<n
def itercomb(n,k):
    if k==0:
        yield 0
    else:
        _a = (1<<k)-1
        yield _a
        while 1:
            _x = _a & -_a
            _y = _a + _x
            _a = (((_a & ~_y) // _x) >> 1) | _y
            if _a >= _ALL: break
            yield _a


xs = []
for _ in range(N):
    xs.append([1<<i for i, x in enumerate(input().split()) if int(x)])
d = [0]*(1<<N)
d[0] = 1
for i, y in enumerate(xs):
    for x in itercomb(N, i):
        for ai in y:
            if (not x&ai):
                d[x|ai] += d[x]%M
                if d[x|ai] >M:
                    d[x|ai]-=M
print(d[-1])


Measured memory_bytes: 57564
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		long a = Integer.parseInt(scan.next());
		System.out.println(factorial(a));
		System.exit(0);
	}
	static long factorial(long i){
		return i == 0 ? 1 : i * factorial(i - 1);
	}
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pcase cout<<"Case "<<++cs<<": "
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define mp make_pair
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()

int main()
{
    int i = 0, j = 0, cs = 0, in;
    ll n; cin>>n;
    cout <<  n*(n-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

#define INF 10000000

using namespace std;

int division(int num, int count) {
	if (num % 2 == 0) {
		count++;
		count = division(num / 2, count);
	}
	return count;
}

int main() {
	int N = 0;
	cin >> N;

	vector<int> A;
	for (int i = 0; i < N; i++) {
		int j = 0;
		cin >> j;

		A.push_back(j);
	}

	int min_count = INF;
	for (const auto& i : A) {
		int count = 0;
		min_count = min(min_count, division(i, count));
	}
	cout << min_count << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	
	int n;
	int count[10] = {};

	FOR(i, 1, 4) {
		cin >> n;
		count[n]++;
	}

	if (count[1] == 1 && count[9] == 1 && count[7] == 1 && count[4] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			double x[] = new double[4];
			double y[] = new double[4];
			double vx[] = new double[4];
			double vy[] = new double[4];
			double gai[] = new double[4];
			String str = in.next();
			StringTokenizer st = new StringTokenizer(str, ",");
			for(int i=0; i<4; i++){
				x[i] = Double.parseDouble(st.nextToken());
				y[i] = Double.parseDouble(st.nextToken());
			}
			for(int i=0; i<4; i++){
				vx[i] = x[(i+1)%4]-x[i];
				vy[i] = y[(i+1)%4]-y[i];
			}
			for(int i=0; i<4; i++){
				gai[i] = (vx[(i+1)%4]*vy[i])-(vy[(i+1)%4]*vx[i]);
			}
			if((gai[0]>0 && gai[1]>0 && gai[2]>0 && gai[3]>0) || (gai[0]<0 && gai[1]<0 && gai[2]<0 && gai[3]<0)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 11000
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> long long inversion(int N, T A[], void *mem=wmem){
  int i;
  int j;
  int k;
  int p;
  int n1;
  int n2;
  T *x;
  T *y;
  long long res = 0;
  walloc1d(&x, N, &mem);
  walloc1d(&y, N, &mem);
  for(i=(0);i<(N);i++){
    x[i] = A[i];
  }
  for(k=0;k<N;k+=4){
    n1 =min_L(4, N-k);
    for(j=n1;j;j--){
      int ZIeRIny5 = j;
      for(i=(1);i<(ZIeRIny5);i++){
        if(x[k+i-1] > x[k+i]){
          swap(x[k+i-1], x[k+i]);
          res++;
        }
      }
    }
  }
  p = 4;
  while(p<N){
    for(k=0;k<N;k+=2*p){
      n1 =min_L(p, N-k);
      n2 =min_L(p, N-k-n1);
      i = j = 0;
      while(i<n1 && j<n2){
        if(x[k+i] <= x[k+n1+j]){
          y[k+i+j] = x[k+i];
          i++;
        }
        else{
          y[k+i+j] = x[k+n1+j];
          res += n1-i;
          j++;
        }
      }
      while(i<n1){
        y[k+i+j] = x[k+i];
        i++;
      }
      while(j<n2){
        y[k+i+j] = x[k+n1+j];
        j++;
      }
    }
    swap(x,y);
    p *= 2;
  }
  return res;
}
int N;
int K;
int A[200000];
long long s[200001];
int main(){
  int i;
  wmem = memarr;
  long long res;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    s[i+1] = s[i] + A[i] - K;
  }
  res = (long long) N * (N+1) / 2 - inversion(N+1, s);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N, K, A[2d5];
// ll s[200001];
// {
//   ll res;
//   rd(N,K,A(N));
//   rep(i,N) s[i+1] = s[i] + A[i] - K;
//   res = (ll) N * (N+1) / 2 - inversion(N+1, s);
//   wt(res);
// }


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

int main() {
  int l,r;
  cin>>l>>r;
  int w;
  int a=l/2019;
  int b=r/2019;
  if (a!=b) {
    w=0;
  } else {
    int p=l%2019;
    int q=r%2019;
    int x=2019*2019;
    for (int i=p;i<=q;++i) {
      for (int j=p;j<i;++j) {
        int y=(i*j)%2019;
        x=min(y,x);
      }
    }
    w=x;
  }
  cout<<w<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){

  int n;
  char in[100]={0};
  while(cin>>n,n){
    int ba=0;
    int pl[10]={0};
    int num=-1;
    cin>>in;
    rep(i,100){
      num++;
      if(num>=n)num=0;
      //cout<<ba<<endl;
      if(in[i]=='M')pl[num]++;
      else if(in[i]=='L'){pl[num]+=1+ba;ba=0;}
      else if(in[i]=='S'){ba+=1+pl[num];pl[num]=0;}
    }
    sort(pl,pl+n);
    rep(i,n)cout<<pl[i]<<" ";
    cout<<ba<<endl;
  }
}

Measured memory_bytes: 1184
let input = require('fs').readFileSync('/dev/stdin', 'utf8');
let Arr = (input.trim()).split("\n");

for(var i = 0;i < Arr.length;++i){
    let n = Arr[i];
    var ans = n % 39;
    if(ans == 0) ans = 39
    if(ans < 10){
        ans = "0" + ans
    }
    console.log("3C"+ ans);
}



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

using ll = long long;

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

    int n;cin>>n;

    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());

    ll ans=0;

    for(int i=0;i<n-2;i++)for(int j=i+1;j<n-1;j++)
    {
        int l=j,r=n;
        for(int m=l+(r-l)/2;m!=l;m=l+(r-l)/2)
        {
            if(a[i]+a[j]>a[m])l=m;
            else r=m;
        }
        ans+=l-j;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3560