akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if( (n|m) == 0 ) break;
			Pair[] ps = new Pair[m];
			for(int i=0;i<m;i++) ps[i] = new Pair(i+1, 0);
			for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
				int a = sc.nextInt();
				ps[j].s += a;
			}
			sort(ps, new Comp());
			System.out.print(ps[0].f);
			for(int i=1;i<m;i++) System.out.print(" " + ps[i].f);
			System.out.println();
		}
	}
	
	class Comp implements Comparator<Pair> {

		@Override
		public int compare(Pair o1, Pair o2) {
			// TODO 自動生成されたメソッド・スタブ
			return o2.s - o1.s;
		}
		
	}
	
	class Pair {
		int f, s;
		Pair(int f, int s) {
			this.f = f;
			this.s = s;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
using System;

public class Hello
{
    static void Main()
    {
        int yen_500 = int.Parse(Console.ReadLine());
        int yen_100 = int.Parse(Console.ReadLine());
        int yen_50 = int.Parse(Console.ReadLine());
        int target_yen = int.Parse(Console.ReadLine());
        int pattern_num = 0;

        for(int i = 0; i <= yen_500; i++)
        {
            for(int j = 0; j <= yen_100; j++)
            {
                for(int k = 0; k <= yen_50; k++)
                {
                    int sum = 500 * i + 100 * j + 50 * k;
                    if (sum == target_yen)
                    {
                        pattern_num++;
                    }
                }
            }
        }

        Console.WriteLine(pattern_num);
    }
}

Measured memory_bytes: 13140
x1, y1, x2, y2 = map(int, input().split())

d_x = x2 - x1
d_y = y2 - y1

d_x, d_y = -d_y, d_x
x3 = x2 + d_x
y3 = y2 + d_y

d_x, d_y = -d_y, d_x
x4 = x3 + d_x
y4 = y3 + d_y

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m;
string s;

int main() {
  cin >> n >> m;
  ll a=1,b=1;
  rep(i,n) a=a*(i+1)%1000000007;
  rep(i,m) b=b*(i+1)%1000000007;
  ll ans;
  if(abs(n-m)>1) ans=0;
  else if(abs(n-m)==1) ans=a*b%1000000007;
  else ans=a*b*2%1000000007;
  cout << ans << endl;
}

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

#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)

int main() {
	int a,b;
	cin>>a>>b;
	int ans=0;
	for (int i = 1; i <= a; ++i){
		int x=31;
		if(i==a)x=b;
		for (int j = 1; j <=x; ++j){
			if(i==j)ans++;
		}
	}
	cout<<ans<<endl;
}

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}


int main(){
    ll n;cin>>n;
    ll tmp;
    vector<ll> a(n);
    ll ans = 0;
    rep(i,n){
        cin>>tmp;
        a.at(i) = tmp;
        ans^=tmp;
    }
    rep(i,n-1){
        tmp = ans^a[i];
        cout<<tmp<<" ";
    }
    tmp = ans^a[n-1];
    cout<<tmp<<endl;



    return 0;
}




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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    
    ll h,a;
    cin>>h>>a;
    cout << (ll)(h+a-1)/a << endl;

}


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

// #define int         long long 
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define endl        "\n"
#define mod         1000000007
#define PI          3.14159265 
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define print(x)    for(auto el: x) cout<<el<<" ";cout<<endl;





void solve(){
    
    int n;
    cin >> n ;

    int a[n], b[n], c[n];
    for(int i=0; i<n; i++)
        cin >> a[i] >> b[i] >> c[i];

    int dp[n][3];
    memset(dp,0,sizeof(dp));

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1; i<n; i++){

        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][2], dp[i-1][0]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }

    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

    return;    
}




int32_t main() 
{
    
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    FIO;
    int test;

    // cin>>test;
    test = 1;
    
    while(test--)
        solve();

    return 0;
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


signed main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	int penalty[n+5]={0};
	int done[n+5]={0};
	int p;
	string s;
	for (int i=0;i<m;i++)
	{
	    
	    cin>>p>>s;
	    if (s=="AC")
	    done[p]=1;
	    
	    else if (s=="WA" && done[p]==0)
	    {
	        penalty[p]++;
	    }
	}
	int pen=0;
	int sc=0;
	for (int i=1;i<=n;i++)
	{
	    sc+=done[i];
	    if (done[i]==1)
	    pen+=penalty[i];
	}
	cout<<sc<<" "<<pen<<endl;
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,ans;
    cin >>S;
    if(S=="A"){
        ans="T";
    }
    if(S=="T"){
        ans="A";
    }
    if(S=="G"){
        ans="C";
    }
    if(S=="C"){
        ans="G";
    }
    cout <<ans<<endl;
}


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

int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2 == 1){
	    cout<<"No"<<endl;
	}else{
	    int d=0;
	   for(int i=0;i<(n/2);i++){
	       if(s[i]==s[(n/2) +i]){
	             d++;    
	       }else{
	           break;
	       }
	   }
	  if(d==(n/2)){
	      cout<<"Yes"<<endl;
	  }else{
	      cout<<"No"<<endl;
	  }
	  
	  }
		return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<deque>
 
using namespace std;
typedef long long ll;
 
int main(void)
{
    int N, L;
    cin >> N >> L;

    int a = L + N - 1;

    int ans = 0;

    if (L < 0)
    {
        if (a < 0)
        {
            for(int i = L; i < a; i++)
            {
                ans += i;
            }
        }
        else
        {
            for(int i = L; i <= a; i++)
            {
                ans += i;
            }
        }
    }
    else
    {
        for (int i = L + 1; i <= a; i++)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    long long int x;
    cin>>x;

    long long int d500=x/500;
long long int lft= x-500*d500;

    long long int zx= (lft/5)*5;

    cout<<1000*d500+zx<<endl;




return 0;


}


Measured memory_bytes: 256
def f(n,k,x):
    if n <= k-1:
        return 0
    dis = [x[i+1]-x[i] for i in range(n-1)]#隣り合う家の距離を調べる
    dis.sort()#電線の数-1だけ隣り合う家同士の電線を配置しなくて良い
    return sum(dis[:n-k])#隣り合う家の距離が大きい順にkー1個は電線を配置しない
    
t = int(input())
for i in range(t):
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    print(f(n,k,x))


Measured memory_bytes: 20856
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
m=100100100100
for i in range(N):
  if abs(A-T+H[i]*0.006)<m:
    m=abs(A-T+H[i]*0.006)
    ans=i
print(ans+1)

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int k,x;
	cin >> k >> x;
	if(k*500 >= x){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void) {
	int a, b;
	char op;
	while(scanf("%d %c %d",&a, &op, &b)!=EOF){
		if(op=='?'){
			break;
		}
	switch(op){
	case '+':
		a=a+b;
		break;
	case '-':
		a=a-b;
		break;
	case '*':
		a=a*b;
		break;
	case '/':
		a=a/b;
		break;
	}
	printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 600
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define ff(i,a,b) for(int i=a;i<=b;++i)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5+5;

int n,a[N][4],dp[N][4];

void solve(){
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=3;j++)
			cin>>a[i][j];
	dp[0][0]=0;
	int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=3;j++){
			if(j==1){
				dp[i][j]=max(dp[i][j],dp[i-1][2]+a[i][2]);
				dp[i][j]=max(dp[i][j],dp[i-1][3]+a[i][3]);
			}
			if(j==2){
				dp[i][j]=max(dp[i][j],dp[i-1][1]+a[i][1]);
				dp[i][j]=max(dp[i][j],dp[i-1][3]+a[i][3]);
			}
			if(j==3){
				dp[i][j]=max(dp[i][j],dp[i-1][2]+a[i][2]);
				dp[i][j]=max(dp[i][j],dp[i-1][1]+a[i][1]);
			}
		}
	}
	cout<<max({dp[n][1],dp[n][2],dp[n][3]});
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while (T--)solve();
}

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

using namespace std;
int n,q;
int niz[450000];
int seg[450000];
void stablo(int ind, int left, int right)
{
    if(left==right)
    {
        seg[ind]=niz[left];
        return;
    }
    int mid=(left+right)/2;
    stablo(ind*2,left,mid);
    stablo(ind*2+1,mid+1,right);
    seg[ind]=min(seg[ind*2],seg[ind*2+1]);
    return;
}
void update(int ind, int left, int right, int poz, int val)
{
    if(left==right)
    {
        seg[ind]=val;
        return;
    }
    int mid=(left+right)/2;
    if(poz<=mid)
    {
        update(ind*2,left,mid,poz,val);

    }
    else
    {
        update(ind*2+1,mid+1,right,poz,val);

    }
    seg[ind]=min(seg[ind*2],seg[ind*2+1]);
    return;
}
long long query(int ind, int left, int right, int l, int r)
{
    if(left>=l && right<=r)
    {
        return seg[ind];
    }
    if(right<l || left>r)
    {
        return INT_MAX;
    }
    int mid=(left+right)/2;
    return min(query(ind*2,left,mid,l,r),query(ind*2+1,mid+1,right,l,r));
}
int main()
{
    //int a=log2(n);
    cin>>n>>q;
    for(int i = 1; i <= n; i++) niz[i] = INT_MAX;
    stablo(1,1,n);
    while(q--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(a==0)
        {
            update(1,1,n,b + 1,c );
        }
        else
        {
            cout<<query(1,1,n,b + 1,c + 1)<<endl;
        }
    }
    return 0;
}

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

#define MAX 500100

int H, A[MAX];

int parent(int i){
    return i / 2;
}

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i + 1;
}

void maxHeapify(int i){
    int l = left(i);
    int r = right(i);
    //左の子，自分，右の子で値が最大のノードを選ぶ
    int largest;
    if(l <= H && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }

    if(r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

void buildMaxHeap(){
    for(int i = H/2; i >= 1; i--){
        maxHeapify(i);
    }
}

void print(){
    for(int i = 1; i <= H; i++){
        printf(" %d", A[i]);
    }
    printf("\n");
}

int main(){
    scanf("%d", &H);
    for(int i = 1; i <= H; i++) cin >> A[i];

    buildMaxHeap();

    print();

    return 0;
}


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

using namespace std;

int main() {
    priority_queue <int> pq;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        pq.push(x);
    }
    while (m > 0) {
        int x = pq.top();
        pq.pop();
        pq.push(x / 2);
        m--;
    }
    long long sum = 0;
    while (pq.size()) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 892
def combination_mod(n, k, mod=10 ** 9 + 7):
    if k > n:
        return 1

    nu, de = 1, 1
    for i in range(k):
        nu = nu * (n - i) % mod
        de = de * (i + 1) % mod
    return nu * pow(de, mod - 2, mod) % mod


n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1
ans -= combination_mod(n, a)
ans = (ans + mod) % mod
ans -= combination_mod(n, b)
ans = (ans + mod) % mod
print(ans)


Measured memory_bytes: 62928
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define clr(a, b) memset(a, b, sizeof(a))
#define Error(x) cout << #x << " = " << x << endl
#define iDEBUG freopen("in.txt", "r", stdin)
#define oDEBUG freopen("output.txt","w",stdout)
#define pb push_back
#define x first
#define y second
#define all(x) x.begin(),x.end()
typedef long long ll;

using namespace std;
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

int main()
{_
    string a, b;
    cin >> a >> b;
    stringstream ss(a+b);
    int num;
    ss >> num;
    int k = sqrt((double)num);
    if(k*k == num)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    ll fib[50];
    rep(i, n+1) {
        if(i == 0 || i == 1) fib[i] = 1;
        else fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;
}



Measured memory_bytes: 3076
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
long long int c=0;
int sgs(long long int a,long long int i,long long int n){
    long long int x,b=a;
    bool three=false,five=false,seven=false;
    if(b>n){
        return 0;
    }else{
        while(b!=0){
            long long int x=b%10;
            b/=10;
            if(x==3) three=true;
            if(x==5) five=true;
            if(x==7) seven=true;
        }
        if(three&&five&&seven) c++;
        three=false,five=false,seven=false;
    }
    //cout << a << " ";
    if(sgs(a+=3*pow(10,i+1),i+1,n)==0){
        a-=3*pow(10,i+1);
    }
    if(sgs(a+=5*pow(10,i+1),i+1,n)==0){
        a-=5*pow(10,i+1);
    }
    if(sgs(a+=7*pow(10,i+1),i+1,n)){
        a-=7*pow(10,i+1);
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    long long int n;
    cin >> n;
    sgs(3,0,n);
    sgs(5,0,n);
    sgs(7,0,n);
    cout << c;
}

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

int main()
{
	for(int r,n;cin>>r>>n && r|n;){
		vector<int> ls(n),rs(n),hs(n);
		for(int i=0;i<n;i++) cin>>ls[i]>>rs[i]>>hs[i];
		vector<int> ys(41);
		for(int i=0;i<n;i++)
			for(int x=ls[i];x<rs[i];x++)
				ys[20+x]=max(ys[20+x],hs[i]);
		
		double res=1e9;
		for(int x=-r+1;x<=r-1;x++){
			double y=-r+sqrt(r*r-x*x);
			res=min({res,ys[20+x]-y,ys[20+x-1]-y});
		}
		printf("%f\n",res);
	}
}

Measured memory_bytes: 1208
from sys import stdin
import itertools 
N,M = [int(x) for x in stdin.readline().rstrip().split()]

edges = []
for m in range(M):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    edges.append((a,b))
    edges.append((b,a))
    
node = list(range(1,N+1))

ans = 0
for i in itertools.permutations(node):
    f = True
    for j in range(len(i)-1):
        if (not (i[j],i[j+1]) in edges):
            f = False
    if f and i[0] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
c = Counter(a)
combi = {}
for k, v in c.items():
   combi[k] = v*(v-1)//2
sumc = sum(list(combi.values()))

for i in range(n):
   x = c[a[i]] - 1
   ans = sumc - combi[a[i]] + x*(x-1)//2
   print(ans)


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0;i < n;i++)
		cin >> v.at(i);
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int b = v.at(0),cnt=1;
	for (int i = 1;i < n;i++) {
		if (b > v.at(i))cnt++,b=v.at(i);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
res = float("inf")

t = [float("inf")] * N
for k in range(N + 1):
  for i in range(N):
    t[(i + k) % N] = min(t[(i + k) % N], a[i])
  res = min(res, sum(t) + k * x)
print(res)


Measured memory_bytes: 42460
import Control.Monad
import Data.Array.Unboxed

main = do
    [n, q] <- map read <$> words <$> getLine
    s      <- getLine
    lr <- forM [1..q] $ \i -> do
        [li, ri] <- map read <$> words <$> getLine
        return (li, ri)
    forM (solve n q s lr) $ \ret -> do
        putStrLn $ show ret

solve :: Int -> Int -> String -> [(Int, Int)] -> [Int]
solve n q s lr = map calc lr
  where
    calc (l, r) = sumArray ! r - sumArray ! l
    sumArray :: UArray Int Int
    sumArray = listArray (0, n) $ doit 0 ' ' s
    doit c p []                           = [c]
    doit c p (h:t) | p == 'A' && h == 'C' = c : doit (c + 1) h t
                   | otherwise            = c : doit c h t

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

int main() {

  int a,b,c,d,e,f;

  cin >> a;

  if(a<1200) {
cout<<"ABC"<<endl;
  }
  else if(a<2800){
cout<<"ARC"<<endl;
  }
          else{
           cout<<"AGC"<<endl;
          }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	
	int ans[n] = {0};
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		
		ans[x - 1]++;
		ans[y - 1]++;
	}
	
	for(int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int dice[7] , side[5] = {2 , 3 , 5 , 4 , 2} ;
    int q , a , b , i , j , k ;
    char order[7][3] = {"" , "" , "N" , "W" , "E" , "S" , "NN"} ;
    
    for(i = 1 ; i < 7 ; i++){
        scanf("%d" , &dice[i]) ;
    }
    scanf("%d" , &q) ;
    
    for(i = 0 ; i < q ; i++){
        scanf("%d %d" , &a , &b) ;
        
        for(j = 1 ; dice[j] != a ; j++) ;
        
            for(k = 0 ; order[j][k] != '\0' ; k++){
                
                dice[0] = dice[1] ;
                
                switch(order[j][k]){
                    
                    case 'E' :
                        dice[1] = dice[4] ;
                        dice[4] = dice[6] ;
                        dice[6] = dice[3] ; 
                        dice[3] = dice[0] ;
                        break ;
                        
                    case 'N' :
                        dice[1] = dice[2] ; 
                        dice[2] = dice[6] ;
                        dice[6] = dice[5] ;
                        dice[5] = dice[0] ;
                        break ;
                        
                    case 'S' :
                        dice[1] = dice[5] ;
                        dice[5] = dice[6] ;
                        dice[6] = dice[2] ;
                        dice[2] = dice[0] ;
                        break ;
                        
                    case 'W' :
                        dice[1] = dice[3] ;
                        dice[3] = dice[6] ;
                        dice[6] = dice[4] ;
                        dice[4] = dice[0] ;
                        break ;
                }
            }
            
            for(j = 0 ; b != dice[side[j]] ; j++) ;
            printf("%d\n" , dice[side[j + 1]]) ;
    }
    return 0 ;
}


Measured memory_bytes: 2052
#include <stdio.h>
int main(void)
{
	int a[7],b[7],i,sa;
	for(i=0;i<7;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<7;i++){
		sa=a[i]-b[i];
		printf("%d\n",sa);
	}
	return 0;
}


Measured memory_bytes: 2124
from math import *
a,b,c=map(int,input().split())
c=c/180*pi
S=0.5*a*b*sin(c)
L=a+b+sqrt(a**2+b**2-2*a*b*cos(c))
h=S*2/a
print('{}'.format(S))
print('{}'.format(L))
print('{}'.format(h))


Measured memory_bytes: 5712
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

int main(void) {

	int n;
	cin >> n;

	map<lli, int> m;

	for (int i = 0; i < n; i++) {
		lli a;
		cin >> a;
		m[a]++;
	}

	for (auto i = m.begin(); i != m.end(); i++) {
		if (i->second >= 2) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 12800
import collections
n = list(map(int,input().split()))

a = [int(input()) for i in range(n[2])]
kk = n[1]-n[2]


counter = collections.Counter(a)

for i in range(n[0]):
    if kk+counter[i+1] <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 11900
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused)]
fn rw<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|word| T::from_str(word).unwrap())
        .collect()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = &[
                $((
                    &stringify!($arg).to_string() as &fmt::Debug,
                    &($arg) as &fmt::Debug,
                )),*
            ];
            eprintln!("{:?}", DebugMap(entries));
        }
    };
}

#[allow(unused)]
struct DebugMap<'a>(&'a [(&'a fmt::Debug, &'a fmt::Debug)]);

impl<'a> std::fmt::Debug for DebugMap<'a> {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        let mut m = fmt.debug_map();
        for &(key, value) in self.0.iter() {
            m.entry(key, value);
        }
        m.finish()
    }
}

// -----------------------------------------------
// Polyfill
// -----------------------------------------------

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused)]
macro_rules! eprintln {
    ($($arg:expr),*) => { _eprintln(format_args!($($arg),*)) }
}

fn _eprintln(args: fmt::Arguments) {
    let err = std::io::stderr();
    let mut err = err.lock();
    err.write_fmt(args).unwrap();
    err.write(b"\n").unwrap();
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let S = rl();
    let mut a = 0;
    let mut b = 0;
    let mut c = 0;
    for ch in S.chars() {
        match ch {
            'a' => a += 1,
            'b' => b += 1,
            'c' => c += 1,
            _ => unreachable!(),
        }
    }

    let n = min(min(a, b), c);
    let mut xs = vec![a - n, b - n, c - n];
    xs.sort();
    let ok = match (xs[0], xs[1], xs[2]) {
        (0, 0, 0) | (0, 0, 1) | (0, 1, 1) => true,
        _ => false,
    };
    println!("{}", if ok { "YES" } else { "NO" });
    return;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ok() {
        assert_eq!(7, 1 + 2 * 3);
    }
}


Measured memory_bytes: 4476
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long X=stdIn.nextLong();
		long a=2;
		boolean key=false;
		while(true){
			for(;a<=Math.sqrt(X);a+=2){
				if(X%a==0){
					key=true;
					break;
				}
				if(a==2)
					a--;
			}
			if(key==false){
				System.out.println(X);
				System.exit(0);
			}
			key=false;X++;a=2;
		}
	}
}


Measured memory_bytes: 22612
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

// reference:
// https://codeforces.com/blog/entry/64250?#comment-523543

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     mt           make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=3e2+5;

ld dp[N][N][N];         // ( no. of 1s, no. of 2s, no. of 3s (remaining) )

int n;

ld rec(int a,int b,int c)
{
    ld k=a+b+c;

    if(!k || a<0 || b<0 || c<0)
        return 0;

    if(dp[a][b][c]!=-1)
        return dp[a][b][c];

    //cout<<a<<" "<<b<<" "<<c<<"\n";

    ld res = n/k + (a/k)*rec(a-1,b,c) + (b/k)*rec(a+1,b-1,c) + (c/k)*rec(a,b+1,c-1);

    return (dp[a][b][c]=res);
}

void solve()
{
    cin>>n;

    for(int i=0;i<=n;++i)
    {
        for(int j=0;j<=n;++j)
        {
            for(int k=0;k<=n;++k)
                dp[i][j][k]=-1;
        }
    }

    int c1=0,c2=0,c3=0;
    int x;
    for(int i=0;i<n;++i)
    {
        cin>>x;

        if(x==1)
            ++c1;
        else if(x==2)
            ++c2;
        else
            ++c3;
    }

    ld ans=rec(c1,c2,c3);
    cout<<fixed<<setprecision(10)<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 438528
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w, k;
    cin >> h >> w >> k;
    vs cake(h);
    rep(i, h) cin >> cake[i];
    
    vvi ans(h, vi(w, -1));
    int now = 1;
    rep(i, h) {
        bool flag = false;
        int cnt = 0;
        rep(j, w) {
            if (cake[i][j] == '#') {
                flag = true;
                cnt++;
            }
        }
        if (!flag) continue;
        rep(j, w) {
            if (cake[i][j] == '#') {
                cnt--;
                if (cnt == 0) {
                    ans[i][j] = now;
                } else {
                    ans[i][j] = now++;
                }
            } else {
                ans[i][j] = now;
            }
        }
        now++;
    }

    rep(i, h-1) {
        if (ans[i+1][0] == -1) {
            if (ans[i][0] != -1) {
                ans[i+1] = ans[i];
            }
        }
    }

    for (int i = h-1; i >= 1; --i) {
        if (ans[i-1][0] == -1) {
            if (ans[i][0] != -1) {
                ans[i-1] = ans[i];
            }
        }
    }

    rep(i, h) {
        rep(j, w) {
            if (j != 0) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <cstdio>
#include <algorithm>

using namespace std;

bool is_square_num(int n) {
    for (int i = 1; i * i <= n; i++) {
        if (i * i == n) { return true; }
    }
    return false;
}

int int_sqrt(int n) {
    for (int i = 1; i * i <= n; i++) {
        if (i * i == n) { return i; }
    }
    fprintf(stderr, "Not square number.\n");
    return -1;
}

int main() {
    for (;;) {
        int h, w;
        scanf("%d%d", &h, &w);

        if (!h && !w) { break; }

        int l = h * h + w * w;

        // i is a variable for the height
        for (int i = h + 1; l - (i * i) > i * i; i++) {
             if (is_square_num(l - i * i)) {
                printf("%d %d\n", i, int_sqrt(l - i * i));
                goto end;
            }
        }

        for (int m = l + 1; ; m++) {
            for (int i = 1; m - (i * i) > i * i; i++) {
                if (is_square_num(m - i * i)) {
                    printf("%d %d\n", i, int_sqrt(m - i * i));
                    goto end;
                }
            }
        }
end:;
    }
    return 0;
}

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

int main(){
  int a,b,t;
  cin >>a >>b >>t;
  int n = t/a;
  cout << b*n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
    int M, T, P, R;
    while (cin >> M >> T >> P >> R&& M + T + P + R){
        int num_solved[T];
        int num_wrong[T][P];
        int total_time[T];

        memset(num_solved, 0, sizeof(num_solved));
        memset(num_wrong, 0, sizeof(num_wrong));
        memset(total_time, 0, sizeof(total_time));

        for (int i = 0; i < R; i++){
            int m, t, p, j;
            cin >> m >> t >> p >> j; t--; p--;
            if (j == 0){
                num_solved[t]++;
                total_time[t] += num_wrong[t][p] * 20 + m;
            } else {
                num_wrong[t][p]++;
            }
        }

        vector<pair<pair<int, int>, int> > vs; 

        for (int i = 0; i < T; i++){
            vs.push_back(make_pair(make_pair(-num_solved[i], total_time[i]), -i)); 
        }
        sort(vs.begin(), vs.end());

        for (int i = 0; i < T; i++){
            if (i > 0){
                if (vs[i].first == vs[i - 1].first){
                    cout << "=";
                } else {
                    cout << ",";
                }
            }
            cout << -vs[i].second + 1 ;
        }
        cout << endl; 
    }
    return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>

int main(void){

  int a,b;

  scanf("%d %d", &a,&b);

  if(a<b){
    printf("a < b");
  };

  if(a>b){
    printf("a > b");
  };

  if(a==b){
    printf("a == b");
  };  

  printf("\n");
  
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll INF = INT_MAX;

int main() {
  int N, M, L;
  cin >> N >> M >> L;

  vector<vector<ll> > vec1(N, vector<ll>(N, INF));

  for(int i=0;i<M;i++) {
    int node1;
    int node2;
    int length;

    cin >> node1 >> node2 >> length;

    vec1[node1-1][node2-1] = length;
    vec1[node2-1][node1-1] = length;
  }

  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(i == j) {
        vec1[i][j] = 0;
      }
    }
  }

  for(int k=0;k<N;k++) {
    for(int i=0;i<N;i++) {
      for(int j=0;j<N;j++) {
        if (vec1[i][j] > vec1[i][k] + vec1[k][j]) {
          vec1[i][j] = vec1[i][k] + vec1[k][j];
        }
      }
    }
  }

  vector<vector<ll> > vec2(N, vector<ll>(N, INF));

  for(int i=0;i<N;i++) {
    for(int j=0;j<N;j++) {
      if(vec1[i][j] <= L) {
        vec2[i][j] = 1LL;
      }
      if(i == j) {
        vec2[i][j] = 0;
      }
    }
  }

  for(int k=0;k<N;k++) {
    for(int i=0;i<N;i++) {
      for(int j=0;j<N;j++) {
        if (vec2[i][j] > vec2[i][k] + vec2[k][j]) {
          vec2[i][j] = vec2[i][k] + vec2[k][j];
        }
      }
    }
  }

  int Q;
  cin >> Q;

  for(int k=0;k<Q;k++) {
    int i, j;
    cin >> i >> j;

    if(vec2[i-1][j-1] < INF) {
      cout << vec2[i-1][j-1] - 1 << endl;
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  int L;
  cin >> L;
  double t = L/3.0;
  cout << fixed << t*t*t << '\n';
}


Measured memory_bytes: 888
#include <stdio.h>
static const int N = 1000;
 
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
      printf("%d", A[i]);
  }   
  printf("\n");
}
 
int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);
 
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
  trace(A, n);
 
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    trace(A, n);
  }
    
  return 0;
}

Measured memory_bytes: 1808
#https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A
import math
import heapq
V,E,r=map(int,input().split())
edge=[[] for _ in range(V)]     # edge[i] : 頂点iからの辺、edge[i][j]:[v,c] 頂点iから頂点vまでの辺、コストc
d=[math.inf for _ in range(V)]  #頂点sからの最短距離

for i in range(E):
    si,ti,di=map(int,input().split())
    edge[si].append([ti,di])
#    edge[ti].append([si,di]) #有向なのでここは無し

#優先度付きキュー
q=[]
heapq.heapify(q)

def dijkstra(start):
    d[start]=0 #初期値
    heapq.heappush(q, [0,start])

    while(len(q)!=0):
        #まだ使われてない頂点のうち距離が最小のものを探す。ない場合は終了
        di=heapq.heappop(q)
        distance=di[0]
        v=di[1]

        if(d[v] < distance):
            continue

        ei = edge[v]
        for i in range(len(ei)):
            e = ei[i]
            if(d[e[0]] > d[v]+e[1]):
                d[e[0]] = d[v]+e[1]
                heapq.heappush(q, [d[e[0]],e[0]])

dijkstra(r)
for i in range(len(d)):
    print(d[i] if d[i]!=math.inf else "INF")



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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<int> cnt(n + 1);
    for (int i = 1; i <= n - 1; i++)
    {
        int t;
        cin >> t;
        cnt[t]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << cnt[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 4000
#include <stdio.h>
#include<iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n, n1,sum = 0;

	cin >> n;
	n1 = n;
	while (n != 0){
		sum +=n % 10;
		n = n / 10;
	}

	if ((n1 % sum) == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;



	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  long long T = 0;
  for (int i = 0; i < (N - K); i++) {
    T += vec.at(i);
  }
  cout << T << endl;
}

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

int main() {
  int w,a,b;cin>>w>>a>>b;
  if (b+w < a) cout << a - (b+w);
  else if (b < a+w) cout << 0;
  else cout << b - (a+w);
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l_max=1
r_min=10**5 
for i in range(m):
  l,r = map(int,input().split())
  l_max = max(l_max,l)
  r_min = min(r_min,r)
ans = r_min - l_max + 1
print(ans if ans >= 0 else 0 )

Measured memory_bytes: 9192
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		HashMap<String, Long>map = new HashMap<String, Long>();

		for (int i=0; i<N; i++){
			String input = sc.next();
			char[] charInput = input.toCharArray();
			String sorted;
			Arrays.sort(charInput);
			sorted = String.valueOf(charInput);
			if (map.containsKey(sorted)){
				map.put(sorted, map.get(sorted)+1);
			} else {
				map.put(sorted, 1L);
			}
		}
		long ans = 0;
		for (long cnt : map.values()){
			ans += combination(cnt);
		}
		System.out.println(ans);
	}

	public static long combination(long cnt){
		long ret = 0;
		for (long i=1; i<=cnt-1; i++){
			ret += i;
		}
		return ret;
	}
}

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

using namespace std;

int N, ans = 0;
char s[309][309];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n", &N);
for (int i=0; i<N; i++)
    scanf ("%s", s[i]);
for (int D = 0; D < N; D ++)
{
    bool ok = 1;
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++)
            if (s[i][j] != s[(j + D) % N][(i + N - D) % N])
            {
                ok = 0;
                i = N;
                break;
            }
    if (ok)
        ans += N;
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 384
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// 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>
#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 <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> v(n);
    map<int,ll> mp;
    ll ans=0;
    rep(i,0,n){
        cin>>v[i];
        v[i]%=m;
        if(i)v[i]+=v[i-1];
        v[i]%=m;
        mp[v[i]]++;
        ans+=mp[v[i]]-1;
        if(v[i]%m==0)ans++;
    }
    cout<<ans<<endl;
}



    

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> f(H,vector<char>(W));
    rep(i,H){
        rep(j,W){
            cin >> f[i][j];
        }
    }
    vector<vector<ll>> dp(H,vector<ll>(W,0));
    dp[0][0]=1;
    queue<Pii> que;
    que.push(Pii(0,0));
    int dh[2]={1,0};
    int dw[2]={0,1};
    while(!que.empty()){
        Pii p=que.front();
        que.pop();
        int h=p.first,w=p.second;
        rep(i,2){
            int nh=h+dh[i],nw=w+dw[i];
            if (nh>=H||nw>=W){
                continue;
            }
            if (f[nh][nw]=='#'){
                continue;
            }
            if (dp[nh][nw]==0){
                que.push(Pii(nh,nw));
            }
            dp[nh][nw]+=dp[h][w];
            dp[nh][nw]%=MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int n, m;  cin >> n >> m;
    int *a = new int[n];
    int cnt = 0, sum = 0;;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; i++) {
        if ((double)a[i] < (double)sum/(double)(4*m))
            continue;
        cnt++;
    }

    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n: usize = read();
  let (s, t): (String, String) = (read(), read());
  
  let mut u = String::new();
  for i in 0..n {
    let si = s.chars().nth(i).unwrap();
    let ti = t.chars().nth(i).unwrap();
    u = format!("{}{}{}", u, si, ti);
  }
  
  println!("{}", u);
}

Measured memory_bytes: 4352
A = []
R = [0]*9
def flag(A):
    if (A[0]*A[1]*A[2]==1)or(A[3]*A[4]*A[5]==1)or(A[6]*A[7]*A[8]==1):
        return 'Yes'
    if (A[0]*A[3]*A[6]==1)or(A[1]*A[4]*A[7]==1)or(A[2]*A[5]*A[8]==1):
        return 'Yes'
    if (A[0]*A[4]*A[8]==1)or(A[2]*A[4]*A[6]==1):
        return 'Yes'
    return 'No'

for i in range(3):
    A += list(map(int, input().split()))
n = int(input())
for i in range(n):
    b = int(input())
    if b in A:
        R[A.index(b)] = 1
print(flag(R))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x;
    cin >> x;
    int i = 0;
    long long n = 100;
    while(1){
        n = n + n / 100;
        //cout << n <<endl;
        i++;
        if (n >= x){
            cout << i << endl;
            break;
        }
    }
    //cout << 1.0 * clock() / CLOCKS_PER_SEC;
    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env ruby

if __FILE__ == $0
	loop do
		h, w = gets.split.map { |x| x.to_i }
		if h == 0 and w == 0 then
			break
		end

		h.times do |i|
			w.times do |j|
				print (i+j) % 2 == 0 ? '#' : '.'
			end
			puts
		end
		puts
	end
end



Measured memory_bytes: 6892
N = int(input())
S = input()

E_count = [0] * (N+1)
W_count = [0] * (N+1)

for i in range(N):
    E_count[i + 1] = E_count[i] + int(S[i] == "E")
    W_count[i + 1] = (i + 1) - E_count[i + 1]

ans = 10 ** 6
for i in range(1, N + 1):
    change_dir_cnt = (W_count[i - 1] - W_count[0]) + (E_count[-1] - E_count[i])
    ans = min(change_dir_cnt, ans)
print(ans)

Measured memory_bytes: 27124
#include <iostream>

using ll = long long;
using namespace std;
int main() {
  ll N, A[100][2];
  cin >> N;
  for (ll j = 0; j < 2; j++) for (ll i = 0; i < N; i++) cin >> A[i][j];

  ll b[100][2];
  b[0][0] = A[0][0];
  b[0][1] = A[0][0] + A[0][1];
  for (ll i = 1; i < N; i++) {
    b[i][0] = b[i - 1][0] + A[i][0];
    b[i][1] = max(b[i - 1][1], b[i][0]) + A[i][1];
  }
  cout << b[N - 1][1] << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	lar := a
	if lar < b {
		lar = b
	}
	var nums []int
	for i := 1; i <= lar; i++ {
		if a%i == 0 && b%i == 0 {
			nums = append(nums, i)
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
	fmt.Println(nums[k-1])

}


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

int main()
{
int A;
int B;
int C;
int D;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;

	if( A > B ) A = B;
	if( C > D ) C = D;

	cout << A + C << endl;

	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  string s;cin >> s;
  int res = 1;
  rep(i,n-1){
    if(s[i] != s[i+1]) res++;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a;
	vector<int> q;
	for (int i = 0; i < n; i++) {
		cin >> a;
		q.emplace_back(a);
	}
	int m;
	cin >> m;
	int p, x;
	for (int i = 0; i < m; i++) {
		cin >> p >> x;
		int ans = 0;
		for (int j = 0; j < n; j++) {
			if (j != p - 1) {
				ans += q[j];
			}
			else {
				ans += x;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int A[100][100],B[100][100];
	int n,m,l,i,j,k;
	long long int C[100][100]={{},{}};

	scanf("%d%d%d",&n,&m,&l);
	for(i=0;i<n;i++)
	  {
		for(j=0;j<m;j++)
	  {
		scanf("%d",&A[i][j]);
	  }
	  }
	for(i=0;i<m;i++)
	  {
		for(j=0;j<l;j++)
	  {
		scanf("%d",&B[i][j]);
	  }
	  }
	for(i=0;i<n;i++)
	  {
		for(j=0;j<l;j++)
	  {
	for(k=0;k<m;k++)
	  { C[i][j]+=A[i][k]*B[k][j];}
	  }
	  }

	for(i=0;i<n;i++)
	  {
		for(j=0;j<l;j++)
	  {
		printf("%lld",C[i][j]);
		if(j!=l-1){printf(" ");}
	  }
		printf("\n");
	  }
	  
	return 0;
}

Measured memory_bytes: 768