akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int square(int x);

int main(void)
{
  int i, a, temp, tcount, sides[3];

  scanf("%d", &tcount);

  for(a=0; a<tcount; a++)
    {
      scanf("%d %d %d", &sides[0], &sides[1], &sides[2]);

      for(i = 0; i < 2; i++)
        {
          if(sides[i + 1] < sides[i])
            {
              temp = sides[i];
              sides[i] = sides[i + 1];
              sides[i + 1] = temp;
            }
        }
        
      if(square(sides[2]) == (square(sides[0]) + square(sides[1])))
        {
          printf("YES\n");
        }else{
          printf("NO\n");
        }
    }

  return 0;
}

int square(int x)
{
  return x * x;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys


def solve(N: int):
    X=int(N/1.08)
    for X in range(X, X+50000):
        if int(X*1.08)==N:
            print(X)
            return
        if X*1.08>N:
            print(":(")
            return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
let n, s = Scanf.scanf " %d %s" @@ fun a b -> a, b
let ans = ref max_int
let ls, rs = Array.make (n + 1) 0, Array.make (n + 1) 0
let _ =
  for i = 0 to n - 1 do ls.(i + 1) <- ls.(i) + if s.[i] = 'W' then 1 else 0 done;
  for i = n - 1 downto 0 do rs.(i) <- rs.(i + 1) + if s.[i] = 'E' then 1 else 0 done;
  for i = 0 to n - 1 do ans := min !ans @@ ls.(i) + rs.(i + 1) done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; string s; cin >> n >> s;
	if(count(s.begin(), s.end(), 'o') == n) cout << string(n, 'S') << endl;
	else if(count(s.begin(), s.end(), 'o') == 0) cout << string(n, 'W') << endl;
	else {
		int i = 0, j = n - 1;
		while(s[i] == s[0]) i++;
		while(s[j] == s[0]) j--;
		auto build = [&](int l, int r, char inr0, char inr1, char inl0, char inl1, bool &ok){
			string nv;
			for(int i = l; i <= r; i++){
				char now;
				if(s[i] == 'x'){
					if(inl1 == 'S'){
						if(inl0 == 'S') now = 'W';
						else now = 'S';
					} else {
						now = inl0;
					}
				} else if(s[i] == 'o'){
					if(inl1 == 'S'){
						now = inl0;
					} else {
						if(inl0 == 'S') now = 'W';
						else now = 'S';	
					}
				}
				inl0 = inl1;
				inl1 = now;
				nv.push_back(inl0);
			}
			ok = inl0 == inr0 && inl1 == inr1;
			return nv;
		};
		auto fx = [&](char c){
			if(s[0] == 'o') return c;
			if(c == 'W') return 'S';
			return 'W';
		};
		int len = i + n - j - 1;
		{
			string opt(len + 2, fx('S'));
			bool good;
			string opt2 = build(i, j, opt[0], opt[1], opt[len], opt[len + 1], good);
			if(good){
				cout <<  opt.substr(n - j, i) + opt2 + opt.substr(1, n - j - 1) << endl;
				return 0;
			}
		}
		{
			string opt(len + 2, fx('S'));
			opt[0] = fx('S');
			opt[1] = fx('W');
			for(int i = 2; i < len + 2; i++) opt[i] = opt[i - 2] == opt[i - 1] ? fx('S') : fx('W');
			bool good;
			string opt2 = build(i, j, opt[0], opt[1], opt[len], opt[len + 1], good);
			if(good){
				cout <<  opt.substr(n - j, i) + opt2 + opt.substr(1, n - j - 1) << endl;
				return 0;
			}
		}
		{
			string opt(len + 2, fx('S'));
			opt[0] = fx('W');
			opt[1] = fx('S');
			for(int i = 2; i < len + 2; i++) opt[i] = opt[i - 2] == opt[i - 1] ? fx('S') : fx('W');
			bool good;
			string opt2 = build(i, j, opt[0], opt[1], opt[len], opt[len + 1], good);
			if(good){
				cout <<  opt.substr(n - j, i) + opt2 + opt.substr(1, n - j - 1) << endl;
				return 0;
			}
		}
		{
			string opt(len + 2, fx('S'));
			opt[0] = fx('W');
			opt[1] = fx('W');
			for(int i = 2; i < len + 2; i++) opt[i] = opt[i - 2] == opt[i - 1] ? fx('S') : fx('W');
			bool good;
			string opt2 = build(i, j, opt[0], opt[1], opt[len], opt[len + 1], good);
			if(good){
				cout <<  opt.substr(n - j, i) + opt2 + opt.substr(1, n - j - 1) << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 776
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true){
			int a = in.nextInt();
			String op = in.next();
			int b = in.nextInt();
			if(op.equals("?"))break;
			int c = 0;
			switch(op){
			case "+":
				c = a+b;
				break;
			case "-":
				c = a-b;
				break;
			case "*":
				c = a*b;
				break;
			case "/":
				c = a/b;
				break;
			}
			System.out.println(c);
        }
        in.close();
	}
}



Measured memory_bytes: 26208
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

coor = [a, b, c, d, e]

flg = False
for i in range(0, 5):
    for j in range(0, 5):
        if abs(coor[i] - coor[j]) > k:
            print(':(')
            exit()
print('Yay!')

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

int main(){
	int w[10],k[10];
	int W=0;
	int K=0;
	for(int i=0;i<10;i++){
		cin>>w[i];
	}
	sort(w,w+10);
	W=w[7]+w[8]+w[9];
	for(int i=0;i<10;i++){
		cin>>k[i];
	}
	sort(k,k+10);
	K=k[7]+k[8]+k[9];
	cout<<W<<" "<<K<<endl;
	return 0;
}

Measured memory_bytes: 1180
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = INT_MAX;

	long N; cin >> N;
	string roku = to_string(mybase(N, 6));

	long mylen = roku.length();

    long nokori;
    string kyuu;
    long kyuulen;
    long resval;
    
	for (long cas = 0; cas < pow(6, mylen); cas++) {
		long sum = 0;
		string casroku = to_string(mybase(cas, 6));
		long caslen = casroku.length();
        
		for (int i = 1; i <= caslen; i++) if (roku[mylen - i] >= casroku[caslen - i]) sum += pow(6, i - 1) * ((int)casroku[caslen - i] - 48); else goto fin ;

		// ここでsumが任意最短の6の出し方になるはず //なった！

		nokori = N - sum;
		kyuu = to_string(mybase(nokori, 9));
		kyuulen = kyuu.length();
		resval = 0;

		for (int i = 0; i < caslen; i++) resval += casroku[i] - 48;
		for (int i = 0; i < kyuulen; i++) resval += kyuu[i] - 48;

		res = min(res, resval);
	fin:;
	}

	cout << res << endl;
}

Measured memory_bytes: 640
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var o = [];
  var n = intShift();
  
  for(var i = 0; i < n ; i++){
  	o.push((function(a){
    	var b = 0;
    	while(a%2==0){
      	b++;
        a/=2;
      }
      return b;
    })(intShift()))
  }
  
  return ~~Math.min(...o);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
6
382253568 723152896 37802240 379425024 404894720 471526144
`);

Measured memory_bytes: 7500
import java.util.Random;
import java.util.Scanner;

//Sequence Configuration
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int[][] c = new int[k][n/2];
		for(int i=0;i<k;i++)for(int j=0;j<n/2;j++)c[i][j]=sc.nextInt();
		Random rand = new Random();
		for(;;){
			int[] a = new int[n+1];
			for(int i=1;i<=n;i++)a[i]=rand.nextInt(2);
			boolean ok = true;
			for(int i=0;i<k;i++){
				if(!ok)break;
				int s = 0;
				for(int j=0;j<n/2;j++){
					if(a[c[i][j]]==1)s++;
					if(3*n/8<s)break;
				}
				if(!(n/8<=s&&s<=3*n/8))ok = false;
			}
			if(ok){
				for(int i=1;i<=n;i++)System.out.print(a[i]+(i==n?"\n":""));
				break;
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long int;
using ll = long long int;

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

    int max = 0;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        string sub = s.substr(i, t.size());
        int num = 0;
        for (int j = 0; j < t.size(); j++) {
            if (sub[j] == t[j]) num++;
        }
        if (max < num) {
            max = num;
        }
    }

    cout << t.size() - max << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include<math.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int sum = 0;
    int w[N];
    for(int i = 0; i < N; i++){
      int tmp = 0;
      cin >> tmp;
      sum += tmp;
      w[i] = tmp;
    }
    int diff = sum;
    int sum1 = 0;
    int sum2 = sum;
    int prev_diff;
    for(int i = 0; i < N; i++){
      prev_diff = diff;
      sum1 += w[i];
      sum2 -= w[i];
      diff = abs(sum1 - sum2);
      if(prev_diff < diff){
        diff = prev_diff;
        break;
      }
    }
    cout << diff << endl;
    return 0;
}


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

Measured memory_bytes: 1080
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string c(26, 'a');
    for (int i = 0; i < 26; i++)
    {
        c[i] = 'a' + i;
    }
    int resul = 0;
    int rescnt = 0;
    for (int i = 1; i < n - 1; i++)
    {
        string s1 = s.substr(0, i);
        string s2 = s.substr(i, n - i);
        int mcnt = 0;
        for (int j = 0; j < 26; j++)
        {
            int res1 = s1.find(c[j]);
            int res2 = s2.find(c[j]);
            if (res1 != -1 && res2 != -1)
            {
                mcnt++;
            }
        }
        if (rescnt < mcnt)
        {
            resul = i;
            rescnt = mcnt;
        }
    }
    cout << rescnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll dp[MAX][15];



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


  cin >> s;
  n = s.size();
  ll cur = 1;
  reverse(all(s));
  dp[0][0] = 1;
  rep(i, n) {
    if (s[i] == '?') {
      rep(k, 10) {
        rep(j, 13) (dp[i + 1][(j + k * cur) % 13] += dp[i][j]) %= mod;
      }
    }
    else {
      ll num = s[i] - '0';
      rep(j, 13) (dp[i + 1][(j + num * cur) % 13] += dp[i][j]) %= mod;
    }
    (cur *= 10) %= 13;
  }
  cout << dp[n][5] << endl;


  return 0;
}


Measured memory_bytes: 12752
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    int N; cin >> N;
    array<int, 100> s = {0};
    for(int i = 0; i < N; i++) cin >> s[i];

    int res = accumulate(begin(s), end(s), 0);
    // debug(res);
    if(res % 10 == 0){
        sort(begin(s), end(s));
        for(auto x: s){
            if(x % 10 != 0){
                res -= x;
                break;
            }
        }
        if(res % 10 == 0) res = 0;
    }

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

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    static int[] max;
    static ArrayList<Integer>[] list;
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int MOD = 1000000007;
		long[][] grid = new long[h][w];
		for(int i = 0; i < h; i++){
		    String s = sc.next();
		    for(int j = 0; j < w; j++){
		        if(s.charAt(j) == '#') grid[i][j] = -1;
		    }
		}
		//System.out.println(Arrays.deepToString(grid));
		
		// 計算
		long result = 0;
		grid[0][0] = 1;
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        if(grid[i][j] == -1){
		            grid[i][j] = 0;
		            continue;
		        }
		        if(i > 0) grid[i][j] += grid[i-1][j];
		        grid[i][j] %= MOD;
		        if(j > 0) grid[i][j] += grid[i][j-1];
		        grid[i][j] %= MOD;
		    }
		}
		
		result = grid[h-1][w-1];
		
		// 出力
		System.out.println(result);
	}
	
	public static int dfs(int i){
	    if(max[i] != 0) return max[i];
	    int dist = 0;
	    for(Integer next : list[i]){
	        dist = max(dist, dfs(next)+1);
	    }
	    max[i] = dist;
	    return dist;
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 36920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, d[200005][26] = {}, b[200005] = {};
    string s, z;
    cin >> s;
    n = (int)s.length();
    for (int i = 0; i < 26; i++) d[n][i] = n + 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) d[i][j] = d[i + 1][j];
        d[i][s[i] - 'a'] = i + 1;
        //for (int j = 0; j < 26; j++) cout << d[i][j] << ' '; cout << '\n';
    }
    for (int i = n; i >= 0; i--) {
        b[i] = 890328;
        for (int j = 0; j < 26; j++) b[i] = min(b[i], b[d[i][j]] + 1);
        //cout << i << ' ' << b[i] << '\n';
    }
    int c = 0;
    for (int i = b[0]; i; i--) {
        int e = 0;
        for (int j = 0; j < 26; j++) if (b[d[c][j]] == i - 1) {e = j; c = d[c][j]; break;}
        z += (char)(e + 'a');
    }
    cout << z;
}


Measured memory_bytes: 21840
program main
implicit none
integer(8) X,Y,Ai,length
 
read(*,*) X,Y
Ai=X
length=1
do
	Ai = Ai+Ai
    if(Ai<=Y)then
	    length = length + 1
    else
    	exit
    endif
enddo
 
write(*,*) length
 
end program

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h=0,m=0,s=0;
		while(S!=0) {
			s++;
			if(s==60) {
				s=0;
				m++;
				if(m==60) {
					m=0;
					h++;
				}
			}
			S--;
		}
		System.out.println(h+":"+m+":"+s);
	}
}



Measured memory_bytes: 26292
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=10000000;
const ll INF=1000000001;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
vector<int> v[100010];
int ma[100010];
int main(){
    int w,h,n;cin>>w>>h>>n;
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v[x].push_back(y);
    }
    for(int i=w-1;i>=1;i--){
        int maa=0;
        for(auto a:v[i]){
            maa=max(a,maa);
        }
        ma[i-1]=max(ma[i],maa);
    }
    int ans=INF;
    for(int i=0;i<w;i++){
        int s=i+ma[i];
        ans=min(s,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8940
# coding: utf-8
# Your code here!

n = int(input())

S = [i for i in range(1, 14)]
H = [i for i in range(1, 14)]
C = [i for i in range(1, 14)]
D = [i for i in range(1, 14)]

for i in range(n) :
    m, r = map(str, input().split())
    
    if m == "S" :
        S.remove(int(r))
    elif m == "H" :
        H.remove(int(r))
    elif m == "C" :
        C.remove(int(r))
    else :
        D.remove(int(r))
        
if len(S) > 0 :
    for i in range(len(S)) :
        print("S", S[i])
if len(H) > 0 :
    for i in range(len(H)) :
        print("H", H[i])
if len(C) > 0 :
    for i in range(len(C)) :
        print("C", C[i])
if len(D) > 0 :
    for i in range(len(D)) :
        print("D", D[i])


Measured memory_bytes: 5624
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
d=deque(list(e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft();v=int(v)
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;print(k,t)


Measured memory_bytes: 18120
f,s,t,i=0,0,0,0
10.times do
	m=gets.to_i
        if f<m
              	m,f=f,m
        end
	if s<m
              	m,s=s,m
        end
	if t<m
              	m,t=t,m
        end
end
puts "#{f}","#{s}","#{t}"

Measured memory_bytes: 6092
/**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                                                               *-*
*-*                  Bismillahir Rahmanir Rahim                   *-*
*-*                                                               *-*
*-*                  Author: Ahsan Habib (comrade)                *-*
*-*                    Metropolitan University                    *-*
*-*                         Language: C++                         *-*
*-*                                                               *-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
#include<bits/stdc++.h>
#include<istream>
#include<cstdio>
#define pii          pair<ll,ll >
#include<string>
#define In freopen("ahsan.txt","r",stdin);
#define ll long long
#define ff first
#define ss second
#define NO cout<<"NO"<<endl
#define m1 cout<<"-1"<<endl
#define No cout<<"No"<<endl
#define cinarr0(n) for(int i = 0;i<n;i++)cin>>a[i];
#define cinarr1(n) for(int i = 1;i<=n;i++)cin>>a[i];
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define pb push_back
#define sorta(a) sort(a,a+n)
#define sortv(v)  sort(v.begin,v.end())
#define bug(a) cerr << #a << " : " << a << endl
#define all(v) (v.begin(), v.end())
#define   sz(x)       x.size()
#define fill(x, y) memset(x, y, sizeof(x))
const int mx = 1e6+5;
const ll md = 1e9+7;
using namespace std;
ll a[200010],m,ans,i,t,k,ev=0,od=0,tt=0,n,cas = 1;
vector<int>vec[mx];
int ar[10000][10000];
vector<pii>v;
bool ok = true;
int main()
{
    //In;
  ///  ios::sync_with_stdio(false);
    ///cin.tie(0);
    ll   n,tot  = 0;

    cin>>n;
    vector<ll>a(n);
    ll ans = 0;
    int md = 1000000007;
    for(int i = 0 ; i <n; i++)
    {
        cin>>a[i];
        tot  = tot + a[i];
        tot = tot % md;
    }


    for(int i = 0 ; i <n; i++)
    {
         tot = tot - a[i];
         if(tot<0)tot+=md;
         ans = ans + a[i]*tot;
         //bug(ans);
         ans = ans%md;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 28344
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    //int T; cin >> T;
    //while(T--) 
 	//{
  //    
  //  }
	ll A,B,C,K;
	cin>>A>>B>>C>>K;
	if(A>=K)
		cout<<K<<endl;
	else if(A+B>=K)
		cout<<A<<endl;
	else
		cout<<A-(K-A-B)<<endl;
	return 0;
}
 



Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
//see answer

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

int main() {
	long long N, M;
	cin >> N >> M;
	long long B = 1;
	long long A;
	cin >> A;
	A /= 2;
	B = A;
	int C = 1;
	while (A % 2 == 0) {
		A /= 2;
		C++;
	}
	bool ans = true;
	for (int i = 1; i < N; i++) {
		cin >> A;
		A /= 2;
		B = lcm(A, B);
		int c = 1;
		while (A % 2 == 0) {
			A /= 2;
			c++;
		}
		if (C != c) ans = false;
	}
	cout << (ans ? ((M / B) + 1) / 2 : 0) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
for _ in range(n):
    a.append(int(input())-1)

j = 0
pointer = 0
b = False
for i in range(n):
    j += 1
    if a[pointer] == 1:
        b = True
        break
    else:
        pointer = a[pointer]

print(j) if b == True else print(-1)

Measured memory_bytes: 13044
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int R;
    cin>>R;
    if(R>=0&&R<1200){
       char i[5]="ABC";
        cout<<i<<endl;
    }
    if(R>=1200&&R<2800){
       char i[5]="ARC";
        cout<<i<<endl;
    }
    if(R>=2800&&R<=4208){
        char i[5]="AGC";
        cout<<i<<endl;
    }
  return 0;  
}


Measured memory_bytes: 256
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
struct node{
	int a,b;
	friend bool operator <(node a,node b){
		return a.a+a.b<b.a+b.b;
	}
} a[5005];
int dp[5005];
int n=read();
signed main(){
	fz(i,1,n)	a[i].a=read(),a[i].b=read();
	sort(a+1,a+n+1);
	fillbig(dp);
	dp[0]=0;
	fz(i,1,n){
		fd(j,i,1){
			if(dp[j-1]<=a[i].a){
				dp[j]=min(dp[j],dp[j-1]+a[i].b);
			}
		}
	}
	fd(i,n,0){
		if(dp[i]<0x3f3f3f3f3f3f3f3fll){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <map>
using namespace std;
map<int,int> m;
int a[200001];
int main(int argc, const char * argv[]) {
   
    int n;
    
    scanf("%d\n",&n);
    
    for(int i=0;i<n;i++){
        
        int tmp;
        scanf("%d",&tmp);
        m[tmp]++;//첫글자로 자동정렬
        a[i]=tmp;
    }
    int med = n/2;
    int sum = 0;
    int num = 0;
    int next = -1;
    for(map<int,int>::iterator it = m.begin(); it!=m.end();it++){
        map<int,int>::iterator tmp=it;
        next = (++tmp)->first;
        sum += it->second;
        if(sum >=med) {
            num = it->first;
            break;
        }
        
    }
    for(int i=0;i<n;i++){
        
        int v = a[i];
        
        if(v <= num){
            if(sum-1 >= med) printf("%d\n",num);//다음위치
            else printf("%d\n",next);
        }else{
            printf("%d\n",num);
        }
        
        
    }
    
    
    return 0;
}


Measured memory_bytes: 12160
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;

    rep(N, 10000)
    {
        if ((A == (N * 8 / 100)) && (B == (N * 10 / 100)))
        {
            cout << N;
            return 0;
        }
    }
    cout << -1;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 1;
  int old = -1;
  for(int i = N;i > 0; i--) {
    if (i % 2 == 0) {
      int j = i;
      int count = 0;
      while (j > 1) {
        j /= 2;
        if (j % 2 == 0){
          count++;
        }
      }
      if(old < count) {
        old = count;
        ans = i;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (row, col, k) = getInts()

    val all = HashMap<Int, HashMap<Int, Int>>()

    val r = HashMap<Int, Int>()
    val c = HashMap<Int, Int>()
    repeat(k) {
        val (x, y) = getInts()
        r[x] = (r[x] ?: 0) + 1
        c[y] = (c[y] ?: 0) + 1

        if (all[x] == null) {
            all[x] = HashMap<Int, Int>()
        }
        all[x]!![y] = 1
    }

    val rr = r.map { it.value to it.key }.sortedByDescending { it.first }
    val rrr = rr.takeWhile { it.first == rr.first().first }
    val cc = c.map { it.value to it.key }.sortedByDescending { it.first }
    val ccc = cc.takeWhile { it.first == cc.first().first }

    rrr.forEach {r0 ->
        ccc.forEach { c0 ->
            if (all[r0.second]?.get(c0.second) == null) {
                println(r0.first + c0.first)
                return
            }
        }
    }
    println(rrr.first().first + ccc.first().first - 1)
}


fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }



Measured memory_bytes: 221728
#include<stdio.h>

int main(void){

  int N=0;
  scanf("%d",&N);
  char S[30001]={};
  scanf("%s",S);
  int pin=0,count=0,i=0,j=0;
  int digit[3];
  
  for(int pin=0;pin<1000;pin++){
    digit[2] = pin%10;
    digit[1] =(pin/10)%10;
    digit[0] = pin/100;
    
    
    for(i=0,j=0;i<N && j<3 ;i++){
    	if(S[i] == '0' + digit[j]){
          j++;
        }
      if(j==3){
      	count++;
      }
    }
  }
  
  printf("%d",count);


 return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int isprime(int n) {
  int i;
  for(i = 2; i * i <= n; i++) {
    if(n % i == 0) return 0;
  }
return 1;
}

int main(){
  int n, i;
  int data[10001];
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i=n ; i >= 5 ; i--){
      if(isprime(i) && isprime(i-2)) break;
    }
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 1740
#include<stdio.h>
static const int N=500;


int main(){
    int A[N][N];
    int a,b,c,d,i,j;
    
    scanf("%d",&a);
    
    for(i=0;i<a;i++){
    for(j=0;j<a;j++){
            A[i][j];
        }
    }
    
    for(i=0;i<a;i++){
        scanf("%d %d",&b,&c);
        b--;
        for(j=0;j<c;j++){
            scanf("%d",&d);
            d--;
            A[b][d]=1;
        }
    }
    
    for(i=0;i<a;i++){
        for(j=0;j<a;j++){
            if(j){
	      printf(" ");
            }
	      printf("%d",A[i][j]);
            }
	printf("\n");
        }
    return 0;
}



Measured memory_bytes: 2108
#include<stdio.h>

int main(){

	int i,temp;
	int n;
	int a,b,c;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		
		if(a < b){temp=a;a=b;b=temp;}
		if(a < c){temp=a;a=c;c=temp;}
		
		if(a*a == b*b + c*c)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1004
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

vector<P> costs[100010];
ll dist[100010];

void dfs(vector<P>* costs, int parent, int node){
    for(P &e : costs[node]){
        if (e.first == parent) continue;
        dist[e.first] = dist[node] + e.second;
        dfs(costs, node, e.first);
    }
}

int main()
{
    int N;
    cin >> N;
    int M = N-1, a, b, c;
    for(int i=0;i<M;++i){
        cin >> a >> b >> c;
        --a;
        --b;
        costs[a].push_back(P(b, c));
        costs[b].push_back(P(a, c));
    }

    int Q, K;
    cin >> Q >> K;
    --K;
    dist[K] = 0;
    dfs(costs, -1, K);
    int x, y;
    for(int i=0;i<Q;++i){
        cin >> x >> y;
        --x;
        --y;
        cout << dist[x] + dist[y] << endl;
    }
}


Measured memory_bytes: 15872
S=input()
N=len(S)
flag1=1
flag2=1
flag3=1
for i in range(N//2):
    if S[i]!=S[N-1-i]:
        flag1=0
s2=S[:(N-1)//2]
s3=S[(N+1)//2:]
#print(s2,s3)
for i in range((N-1)//4):
    if s2[i]!=s2[((N-1)//2)-1-i]:
        flag2=0
    if s3[i]!=s3[((N-1)//2)-1-i]:
        flag3=0
if flag1+flag2+flag3==3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <array>

using namespace std;

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

    vector<vector<int>> t(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        t[l][r]++;
    }

    vector<vector<int>> s(n + 1, vector<int>(n + 1, 0));
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            s[i][j] += s[i][j - 1];
            for (int k = i; k <= j; k++) {
                s[i][j] += t[k][j];
            }
        }
    }

    for (int i = 0; i < q; i++) {
        int p, q;
        cin >> p >> q;
        cout << s[p][q] << endl;
    }
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int gcd(int a,int b);
int compare(const void* a, const void* b);

typedef struct {
    int pos;
    int vit[100];
}PA;

int main(void){
    int N;
    int X[100];
    int sum[100];
    int min = 1000000;
    int i,j,k;
    scanf("%d",&N); //人数
    for( i = 0 ; i < N ; i++){
        scanf("%d",&(X[i]));    // i番目の人はどこにいる？
    }
    for( i = 0 ; i < 100 ; i++){ // i番目で実行したときの全員の消費体力
        sum[i] = 0;
        for( k = 0 ; k < N;k++){
            sum[i] = sum[i] + (X[k] - i)*(X[k] - i);
        }
        if (min>sum[i]) min = sum[i];
    }
    printf("%d\n",min);
    return 0;
}
int compare(const void* a, const void* b){
    return strcmp(a, b);
}
// 最大公約数
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(){
int i,n,m,c,count=0;
  cin>>n>>m>>c;
  int a[m],b[m];
  	for(i=0;i<m;i++)
    {
		cin>>b[i];
    }
  while(n--)
  {
    int s=0;
	for(i=0;i<m;i++)
    {
		cin>>a[i];
    }
    
    for(i=0;i<m;i++)
    {
		s+=a[i]*b[i];
    }
    if(s+c>0)
      count++;
  }
  cout<<count;
    return 0;
}
    
      
    

Measured memory_bytes: 3624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

"""
・最小カット
・頂点でカットする場合には、v_in, v_outに分ける
・v_in, v_outの間に容量1の辺
・sourceから、ヤギ_outに容量無限大の辺
・外周_outから、sinkに容量無限大の辺
"""

class Dinic:
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
        
    def add_edge_undirected(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, cap, n1])
        
    def bfs(self):
        level = [0] * self.N
        G = self.G; source = self.source; sink = self.sink
        q = deque([source])
        level[source] = 1
        pop = q.popleft; append = q.append
        while q:
            v = pop()
            lv = level[v] + 1
            for to, cap, rev in G[v]:
                if not cap:
                    continue
                if level[to]:
                    continue
                level[to] = lv
                if to == sink:
                    self.level = level
                    return
                append(to)
        self.level = level
        
    def dfs(self,v,f):
        if v == self.sink:
            return f
        G = self.G
        prog = self.progress
        level = self.level
        lv = level[v]
        E = G[v]
        for i in range(prog[v],len(E)):
            to, cap, rev = E[i]
            prog[v] = i
            if not cap:
                continue
            if level[to] <= lv:
                continue
            x = f if f < cap else cap
            ff = self.dfs(to, x)
            if ff:
                E[i][1] -= ff
                G[to][rev][1] += ff
                return ff
        return 0
    
    def max_flow(self):
        INF = 10**18
        flow = 0
        while True:
            self.bfs()
            if not self.level[self.sink]:
                return flow
            self.progress = [0] * self.N
            while True:
                f = self.dfs(self.source, INF)
                if not f:
                    break
                flow += f
        return flow

H,W = map(int,readline().split())
S = b''.join(read().split())

# v_i-in: 2i
# v_i-out: 2i+1
source = 2*H*W
sink = source+1

INF = 10**12

dinic = Dinic(2*H*W+2,source,sink)
add = dinic.add_edge
for i in range(H*W):
    h,w = divmod(i,W)
    if S[i] == ord('.'):
        add(i+i,i+i+1,1)
    else:
        add(source,i+i+1,INF)
    for dh,dw in ((1,0),(-1,0),(0,1),(0,-1)):
        h1 = h + dh; w1 = w + dw
        if 0 <= h1 < H and 0 <= w1 < W:
            j = h1 * W + w1
            add(i+i+1,j+j,1)
        else:
            # 画面外
            add(i+i+1,sink,INF)

f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)

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

int main() {
  int n;
  cin >> n;
  int a = pow(3, n), b = 1;
  for (int i = 0; i < n; i ++) {
    int t; cin >> t;
    if (t % 2 == 0) b *= 2;
  }

  cout << a - b << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

int gcd2(int a,int b)
{
    if(b==0)return a;
    return gcd2(b,a % b);
}

int main()
{
    int K;
    cin >> K;
    long long sum;
    sum = 0;
    long long gcd;
    for(int a=1;a<K+1;a++){
        for(int b=1;b<K+1;b++){
            for(int c=1;c<K+1;c++){
                gcd = gcd2(a,b);
                gcd = gcd2(gcd,c);
                sum = sum + gcd;
            }
        }
    }
    cout << sum;

    
    return 0;
    
}

Measured memory_bytes: 3636
from collections import Counter
while True:
    N = int(input())
    if not N:
        break
    C = input().split()
    for i in range(N):
        cnt = Counter(C[:i+1]).most_common() + [('', 0)]
        if cnt[0][1] > cnt[1][1] + N - i - 1:
            print(cnt[0][0], i + 1)
            break
    else:
        print("TIE")

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

int main() {
  string s;
  string t;
  int cnt=0;
  cin >> s >> t;
  rep(i,3){
    if(s[i] == t[i]) cnt++;
  }
  
  cout << cnt << endl;
  
  return(0);
}


Measured memory_bytes: 3608
s= input()
t= input()
n=len(s)
m= len(t)
dp = [[0 for i in range(n+1)] for j in range(m+1)]
for j in range(1,n+1):
    for i in range(1,m+1):
        if s[j-1]==t[i-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i =n
j=m
inde = dp[m][n]
an = [""] * (inde +1)
while i>0 and j>0:
    if s[i-1]==t[j-1]:
        an[inde-1]=s[i-1]
        i-=1
        j-=1
        inde-=1
    elif dp[j-1][i]>dp[j][i-1]:
        j-=1
    else:

        i-=1
print(''.join(an))


Measured memory_bytes: 152800
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int n;
int a1 = 0;
int a2 = 0;
int a3 = 0;
vector<vector<vector<double>>> dp(310, vector<vector<double>>(310, vector<double>(310)));
int main(){
    cin >> n;
    rp(i, 0, n){
        int a;
        cin >> a;
        if(a == 1) a1++;
        else if(a == 2) a2++;
        else if(a == 3) a3++;
    }
    dp.at(1).at(0).at(0) = 1;
    dp.at(0).at(1).at(0) = 2;
    dp.at(0).at(0).at(1) = 3;
    rp(i, 2, a1+a2+a3+10){
        for(int j=i; j >= 0; j--){
            for(int k=i-j; k >= 0; k--){
                if(j >= 1) dp.at(j).at(k).at(i-j-k) += dp.at(j-1).at(k).at(i-j-k)*j*i/(i-1);
                if(k >= 1) dp.at(j).at(k).at(i-j-k) += dp.at(j+1).at(k-1).at(i-k-j)*k;
                if(i-j-k >= 1) dp.at(j).at(k).at(i-j-k) += dp.at(j).at(k+1).at(i-k-j-1)*(i-j-k);
                dp.at(j).at(k).at(i-j-k) = dp.at(j).at(k).at(i-j-k) / i + 1;
            }
        }
    }   

    cout << fixed << setprecision(12) << dp.at(a1).at(a2).at(a3) << endl;
    return 0;
}


Measured memory_bytes: 237568
#include <bits/stdc++.h>
using namespace std;
int main(){
  int c,q,i,j,z=0,k=1,o=0,m[1001][1001]={0},e[6][2]={0};
  for(i=0;i<6;i++){
    cin>>q>>c;
    if(q>c)m[q][c]++;
    else m[c][q]++;
  }
  for(i=0;i<1001;i++)for(j=0;j<1001;j++){
    if(m[i][j]){
      if(m[i][j]==4){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
      else if(m[i][j]==6){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
      else{ e[z][0]=i;e[z++][1]=j;}
    }
  }
  if(e[0][0]!=e[2][1]||e[1][0]!=e[2][0]||e[0][1]!=e[1][1])k=0;
  if(k)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    int X; cin >> X;
    int n = 1;
    while(n < 10000){
        if(100*n <= X && X <= 105*n){
            cout << 1 << endl;
            return 0;
        }
        n++;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
//template
import java.util.*;
import java.util.stream.Stream;
import java.io.*;
public class Main{
	static BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	public static void main(String[] args) throws IOException{
		
		String line=in.readLine();
		long sum=0;
		for(long i=0;i<line.length();i++)
			sum+=Long.parseLong(line.charAt((int) i)+"");
		if(sum%9==0)
			out.append("Yes");
		else
			out.append("No");
		
		out.flush();
		in.close();
		out.close();
	}
	public static boolean palindrome(String s) {
		boolean palindrome=true;
		int i=0,j=s.length()-1;
		while(i<j&&palindrome) {
			if(s.charAt(i++)!=s.charAt(j--))
				palindrome=false;
		}
		return palindrome;
	}
	public static long reverse(String s) {
		String aux="";
		for(int i=s.length()-1;i>=0;i--) {
			aux+=s.charAt(i);
		}
		return Long.parseLong(aux);
	}
	private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2
	private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; }
	private static int[] readInts() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	}
	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}
	private static long[] readLongs() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	}
	private static long readLong() throws IOException {
		return Long.parseLong(in.readLine());
	}
	 
}

Measured memory_bytes: 46752
fun main(args: Array<String>) {
    val x = readLine()!!.toDouble()
    var ans = 0.0
    (1..Math.sqrt(x).toInt()).forEach {
        val b = it.toDouble()
        var s = 0.0
        for (p in 2..9) {
            val t = Math.pow(b, p.toDouble())
            if (x < t) break
            s = t
            if (x == t) break
        }
        ans = Math.max(ans, s)
    }
    println(ans.toInt())
}


Measured memory_bytes: 33648
#include<stdio.h>
#include<stdlib.h>
void initArr(int*,int);
int toIndex(char);
void showCount(int*);
int main(void)
{
  char c;
  int countArr[26];
  int index;
  initArr(countArr,26);
  while(scanf("%c",&c)!=EOF)
    {
      index=toIndex(c);
      if(index==-1) continue;
      countArr[index]++;
    }
  showCount(countArr);
  return 0;
}
void initArr(int *arr,int n)
{
  int i;
  for(i=0;i<n;i++) arr[i]=0;
}
int toIndex(char c)
{
  if(c>='A'&&c<='Z') c+='a'-'A';
  if(c>='a'&&c<='z') return c-'a';
  else return -1;
}
void showCount(int *countArr)
{
  int i;
  for(i=0;i<26;i++) printf("%c : %d\n",i+'a',countArr[i]);
}


Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main () {
  int n;
  string str;
  cin >> n >> str;

  vector<int> leftStartW(n, 0);
  vector<int> rightStartE(n, 0);

  leftStartW[0] = str[0] == 'W' ? 1 : 0;
  for (int i = 1; i < n; i++) {
    if (str[i] == 'W') {
      leftStartW[i] = 1 + leftStartW[i-1];
    } else {
      leftStartW[i] = leftStartW[i-1];
    }
  }

  rightStartE[n-1] = str[n-1] == 'E' ? 1 : 0;
  for (int i = n-2; i >= 0; i--) {
    if (str[i] == 'E') {
      rightStartE[i] = 1 + rightStartE[i+1];
    } else {
      rightStartE[i] = rightStartE[i+1]; 
    }
  }

  int ansNum = n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    if (i == 0) {
      tmp = rightStartE[1];
    } else if (i == n - 1) {
      tmp = leftStartW[n-2];
    } else {
      tmp = leftStartW[i - 1] + rightStartE[i + 1];
    }
    if (tmp < ansNum) {
      ans = i;
      ansNum = tmp;
    }
  }
  cout << ansNum << endl;
  return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean c = true;
		if(s.charAt(0) != 'A' || s.substring(2, s.length()).split("C").length != 2) c = false;
		char[] set = s.toCharArray();
		if(c)for(int i = 1; i < set.length; i++) {
			if(set[i] != 'C' && !Character.isLowerCase(set[i])) {
				c = false;
				break;
			}
		}
		if(c)System.out.println("AC");
		else System.out.println("WA");
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b;
	t = 1;
	while(t--) {
	 cin >> a >> b;
	 if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
	  cout << "Possible" << endl;
	 else
	  cout << "Impossible" << endl;
	}
	return 0;
}



Measured memory_bytes: 256