akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

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

    int h, w;
    cin >> h >> w;

    int a[h][w];
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }

    vector<pair<pint,pint>> ans;
    int cnt = 0;
    int t = 0;
    rep(i, h){
        rep(j, w){
            ++t;
            if(t == h*w) break;
            if(i%2){

                if(a[i][w-1-j]%2){
                    a[i][w-1-j]--;
                    ++cnt;
                    if(j != w-1){
                        a[i][w-2-j]++;
                        ans.push_back(make_pair(make_pair(i+1, w-j),make_pair(i+1, w-j-1)));
                    }
                    else{
                        a[i+1][w-1-j]++;
                        ans.push_back(make_pair(make_pair(i+1, w-j),make_pair(i+2, w-j)));
                    }
                }
            }
            else{
                if(a[i][j]%2){
                    a[i][j]--;
                    ++cnt;
                    if(j != w-1){
                        a[i][j+1]++;
                        ans.push_back(make_pair(make_pair(i+1, j+1),make_pair(i+1, j+2)));
                    }
                    else{
                        a[i+1][j]++;
                        ans.push_back(make_pair(make_pair(i+1, j+1),make_pair(i+2, j+1)));
                    }
                }
            }

        }
    }

    ppp(cnt);
    for(auto yx : ans){
        cout << yx.first.first << sp << yx.first.second << sp << yx.second.first << sp << yx.second.second << endl;
    }



    return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(X) (X).begin(),(X).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int dis = 0;
    a.push_back(a[0]+k);
    rep(i,n) dis = max(dis, a[i+1]-a[i]);
    int ans = k - dis;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2300
import sys
input=sys.stdin.readline

def main():
    N,W = map(int, input().split())
    w = []
    v = []
    for _ in range(N):
        x,y = map(int, input().split())
        w.append(x)
        v.append(y)

    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(W+1):
            if j - w[i] >= 0:
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])
            else:
                dp[i+1][j] = dp[i][j]
                
    ans = 0
    for a in dp:
        ans = max(ans, max(a))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 120048
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
bool use[101];
int tot;
int main()
{
	int n,k,d,a;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>d;
		for(int j=1;j<=d;j++)
		{
			cin>>a;
			use[a]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(!use[i]) tot++;
	}
	cout<<tot;
 } 

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

MOD = 1000000007  # type: int

def c(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


def solve(N: int, K: int):
    for i in range(1,K+1):
        print((c(K-1, i-1) * c(N-K+1, i)) % MOD)
    return


# Generated by 1.1.4 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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4584
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
int a[1000000];

int f(int n){
    int sum=0;
   for(int i=0;i<=n;i++)a[i]=1;
   for(int i=2;i<=n;i++){
      if(a[i]==1){
         sum++;
         for(int j=2*i;j<=n;j+=i)
            a[j]=0;                        
      }        
   }
    return sum;
}

int main()
{
    int n;
    while(cin>>n){
       cout<<f(n)<<endl;              
    }
    return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int a, b;
    cin >> a >> b;
    string ans;
    if (a < b) ans = "a < b";
    else if (a > b) ans = "a > b";
    else ans = "a == b";
    cout << ans << endl;
}



Measured memory_bytes: 3204
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int>
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size()
	#define PI 3.14159265358979323846

	const int N =2e5+5;

     int mod= 998244353;
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};

      int maxi;
      
    void solve(){
             int q,tt=0;
             cin>>q;
            
            map<vi,int >mp;
            
            while(q--){
               string s;
               cin>>s;
              vi h(26,0);
              rep(i,0,sz(s))
                h[s[i]-'a']++;
              
              mp[h]++;                                
            }
            
            
            for(auto to:mp){
                tt+=(to.se*(to.se-1))/2;
            }
                        
            
            cout<<tt<<endl;
            
     }
       
       
	int32_t main() {

	  cool;
	  int t=1;
     // cin>>t;


	  while (t--)
		 solve();

	  return 0;
	}


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

using namespace std;
typedef long long ll;

// #define DEBUG

struct node
{
    int id = 0;
    int parent = -1;
    int sibling = -1;
    int left = -1;
    int right = -1;
    int degree = 0;
    int depth = -1;
    int height = -1;
    string status = "unknown";
};

void nodeproperty(node &x)
{
    if (x.left != -1)
        x.degree++;
    if (x.right != -1)
        x.degree++;

    if (x.parent == -1)
    {
        x.status = "root";
        if (x.degree == 0)
            x.height = 0;
    }
    else if (x.degree != 0)
        x.status = "internal node";
    else
    {
        x.status = "leaf";
        x.height = 0;
    }
}

void getdepth(node x[], int n)
{
    vector<int> search, new_search;
    int d = 0;
    for (int i = 0; i < n; i++)
    {
        if (x[i].status == "root")
            search.push_back(i);
    }
    while (!search.empty())
    {
        for (auto itr = search.begin(); itr != search.end(); itr++)
        {
            x[*itr].depth = d;
            if (x[*itr].left != -1)
                new_search.push_back(x[*itr].left);
            if (x[*itr].right != -1)
                new_search.push_back(x[*itr].right);
        }

        search.clear();
        search = new_search;
        new_search.clear();
        d++;
    }
}

void getheight(node x[], int n)
{
    vector<int> search, new_search;
    int h = 0;
    for (int i = 0; i < n; i++)
    {
        if (x[i].status == "leaf")
            search.push_back(i);
    }
    while (!search.empty())
    {
        for (auto itr = search.begin(); itr != search.end(); itr++)
        {
            x[*itr].height = h;
            if (x[*itr].parent != -1)
                new_search.push_back(x[*itr].parent);
        }

        search.clear();
        search = new_search;
        new_search.clear();
        h++;
    }
}

void printnode(node x)
{
    cout << "node " << x.id << ": parent = " << x.parent;
    cout << ", sibling = " << x.sibling << ", degree = ";
    cout << x.degree << ", depth = " << x.depth << ", height = ";
    cout << x.height << ", " << x.status << endl;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, id, left, right;
    cin >> n;
    node tree[n];
    for (int i = 0; i < n; i++)
    {
        cin >> id >> left >> right;
        tree[i].id = i;
        tree[id].left = left;
        tree[id].right = right;
        tree[left].parent = id;
        tree[left].sibling = right;
        tree[right].parent = id;
        tree[right].sibling = left;
    }

    for_each(tree, tree + n, &nodeproperty);
    getdepth(tree, n);
    getheight(tree, n);
    for_each(tree, tree + n, printnode);
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3212
#include <iostream>
int main(){
    int a,b,c;
    std::cin>>a>>b>>c;
    if(a+b>=c){
        if(a>=c){
            std::cout<<0<<std::endl;
        }else{
            std::cout<<c-a<<std::endl;
        }
    }else{
        std::cout<<"NA"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include<stdio.h>

//お年玉演習

int main() {
    int a, b; //Aくん、Bくん
    
    //入力
    //printf("A B = ");
    scanf("%d %d", &a, &b);
    
    //出力
    printf("%d\n", (a+b)/2);
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vint x(5);
    rep(i, 5) cin >> x[i];
    rep(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int MAX_N = 21;
const int MAX_S = 8200;

int n, s;
vector<int> vec;
int map[MAX_N][MAX_S];

int dp(int y, int x);

int main(){
    while(cin >>n){
        if(n == 0) break;
        memset(map, -1, sizeof(map));
        vec = vector<int>(n * 2 + 1);
        //vec.clear();
        cin >>s;
        for(int i = 1; i <= (n * 2); i++) cin >>vec[i];
        cout <<dp(1, s) <<endl;
    }
    return 0;
}

//y ... 人, x ... 石
int dp(int y, int x){
    if(map[y][x] != -1) return map[y][x];
    //自分チームのターン
    if(y % 2 == 1){
        if(x <= 1) return map[y][x] = 0;
        int ny = y + 1;
        //if(ny > (n * 2)) ny = 1;
        for(int i = 1; i <= vec[y]; i++){
            if(x - i > 0){
                if(dp(ny, x - i)) return map[y][x] = 1;
            }
        }
        return map[y][x] = 0;
        //相手チームのターン
    } else{
        if(x <= 1) return map[y][x] = 1;
        int ny = y + 1;
        if(ny > (n * 2)) ny = 1;
        for(int i = 1; i <= vec[y]; i++){
            if(x - i > 0){
                if(!dp(ny, x - i)) return map[y][x] = 0;
            }
        }
        return map[y][x] = 1;
    }
}

Measured memory_bytes: 2228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]

using namespace std;
using ll = long long;

int main(void){
    unordered_map<char, ll> a;
    Cin(int, n);
    For(i, n){
        Cin(string, s);
        a[s[0]] ++;
    }
    Cout(
        a['M']*a['A']*a['R'] + a['M']*a['A']*a['C'] + a['M']*a['A']*a['H'] + a['M']*a['R']*a['C'] + a['M']*a['R']*a['H'] +
        a['M']*a['C']*a['H'] + a['A']*a['R']*a['C'] + a['A']*a['R']*a['H'] + a['A']*a['C']*a['H'] + a['R']*a['C']*a['H']);
}


Measured memory_bytes: 256
#include<iostream>
  using namespace std;
   int main(){
      int a[10];
      int temp;
      for(int m=0; m<10; m++)
      {
          cin >> a[m];
      }
    temp=a[0];
      for(int i=0; i<10; i++)
      {
          for(int j=0; j<10;j++)
          {
          if(a[i] > a[j])
          {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
          }
        }
      }
      for(int k=0; k<3; k++)
      {
          cout << a[k]<< endl;
      }
   }

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a=new long[N];
        for(int i=0; i<N; i++){
            a[i]=sc.nextLong();
        }

        Arrays.sort(a);

        long count=a[N-1];
        int p=0;
        int q=2;
        for(int i=2; i<N; i++){
            count = count + a[N-q];
            p++;
            if(p==2){
                p=0;
                q++;
            }
        }
        
        System.out.println(count);
        
        
        
        
        
        }
    }

Measured memory_bytes: 62052
// JOI2015Pre Russian Flag
#include <iostream>

using namespace std;

int main(){

  int N,M;
  cin >> N >> M;
  
  int A[51][3]={0};  
  for(int i=0;i<N;i++)
    for(int j=0;j<M;j++){
      char c;
      cin >> c;
      if(c=='W') A[i][0]++;
      else if(c=='B') A[i][1]++;
      else A[i][2]++;
    }

  int ans=N*M;
  for(int i=1;i<N-1;i++)
    for(int j=i;j<N;j++){
      int change=0;
      for(int k=0;k<i;k++) change+=(M-A[k][0]);
      for(int k=i;k<j;k++) change+=(M-A[k][1]);
      for(int k=j;k<N;k++) change+=(M-A[k][2]);
      if( change < ans) ans = change;
    }

  cout << ans <<endl;

  return 0;
}



Measured memory_bytes: 3084
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in(N);

    vll P(N);
    inN(P, N);

    vll Q(N);
    inN(Q, N);

    vll A(N);
    rep(i, N) A[i] = P[i];

    
    ll cnt1 = 0;
    ll cnt2 = 0;

    sort(all(A));

    do
    {
        bool flg = true;

        rep(i, N)
        {
            if (A[i] != P[i])
            {
                flg = false;
                break;
            }   
        }

        if (flg)
        {
            break;
        }

        cnt1++;

    } while (next_permutation(all(A)));

    sort(all(A));

    do
    {
        bool flg = true;

        rep(i, N)
        {
            if (A[i] != Q[i])
            {
                flg = false;
                break;
            }
        }

        if (flg)
        {
            break;
        }

        cnt2++;

    } while (next_permutation(all(A)));

    outl(abs(cnt1 - cnt2));

    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		//??\???
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long[][] C = new long[n][l];
		for (int ni=0; ni < n; ni++) {
			for (int mi=0; mi < m; mi++) {
				A[ni][mi] = sc.nextInt();
			}
		}
		for (int mi=0; mi < m; mi++) {
			for (int li=0; li < l; li++) {
				B[mi][li] = sc.nextInt();
			}
		}
		//?¨????
		for (int ni=0; ni < n; ni++) {
			for (int li=0; li < l; li++) {
				for (int mi=0; mi < m; mi++) {
					C[ni][li] += A[ni][mi] * B[mi][li];
				}
			}
		}
		//??????
		for (int ni=0; ni < n; ni++) {
			for (int li=0; li < l; li++) {
				System.out.print(C[ni][li]);
				if (li < l-1) {
					System.out.print(" ");
				}
			}
			System.out.println("");
		}

	}

}

Measured memory_bytes: 53360
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&a==c)
	{
	printf("1\n");
//	printf("One different color:%d.\n",a);
}
	if(a==b&&a!=c)
 {
 printf("2\n"); 
  // printf("Two different colors:%d and %d.\n",a,c);
}
    if(a==c&&a!=b)
   {
   printf("2\n");
    //printf("Two different colors:%d and %d.\n",a,b);
}
    if(b==c&&a!=b)
   {
   printf("2\n");
    //printf("Two different colors:%d and %d.\n",a,b);
}
    if(a!=b&&a!=c&&b!=c)
 {
 printf("3\n");
    //printf("Three different colors:%d,%d,and%d.\n",a,b,c);
}
	return 0;
 } 

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int M=50;
const int N=1010;
int x[N],y[N];
int abs(int x)
{
	return x>0?x:-x;
}
int t;
int d[M];
char ans[N][M];
int n;
void gao(int k)
{
	t++;
	d[t]=k;
	for(int i=1;i<=n;i++)
		if(abs(x[i])>abs(y[i]))
		{
			if(x[i]>0)
			{
				x[i]-=k;
				ans[i][t]='R';
			}
			else
			{
				x[i]+=k;
				ans[i][t]='L';
			}
		}
		else
		{
			if(y[i]>0)
			{
				y[i]-=k;
				ans[i][t]='U';
			}
			else
			{
				y[i]+=k;
				ans[i][t]='D';
			}
		}
}
int main()
{
	open2("d");
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=30;i>=0;i--)
		gao(1<<i);
	for(int i=1;i<=8;i++)
		gao(1);
	if(x[1]||y[1])
		gao(1);
	for(int i=1;i<=n;i++)
		if(x[i]||y[i])
		{
			printf("-1\n");
			return 0;
		}
	printf("%d\n",t);
	for(int i=1;i<=t;i++)
		printf("%d ",d[i]);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%s\n",ans[i]+1);
	return 0;
}

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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int Amin(int *p,int size){
   int _min = inf;
   for(int i = 0;i < size;i++)
      if(p[i] < _min)_min = p[i];
   return _min;
}
int Amax(int *p,int size){
   int _max = 0;
   for(int i = 0;i < size;i++)
      if(p[i] > _max)_max = p[i];
   return _max;
}
int main(){
   int n;scanf("%d",&n);
   int a[100];for(int i = 0;i < n;i++)scanf("%d",&a[i]);
   printf("%d",Amax(a,n)-Amin(a,n));
}

Measured memory_bytes: 128
// Aizu Vol-1 0126: Puzzle
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char *gets(char *);
char buf[200];

char a[9][9];
char ans[9][9];
char cnt[15];

void getData(int r)
{
	int c;
	char *p = buf;
	for (c = 0; c < 9; c++) {
		while (isspace(*p)) p++;
		a[r][c] = *p++ - '0', ans[r][c] = ' ';
	}
}

int main()
{
	int i, k, n, r, c, r2, c2, rr, cc;

	gets(buf);
	n = atoi(buf);
	for (i = 0; i < n; i++) {
		if (i > 0) putchar('\n');
		for (r = 0; r < 9; r++) {
			gets(buf);
			getData(r);
		}
		for (r = 0; r < 9; r++) {
			memset(cnt, 0, 10);
			for (c = 0; c < 9; c++) {
				k = a[r][c];
				if (!cnt[k]) cnt[k] = c + 1;
				else {
					ans[r][c] = '*';
					c2 = cnt[k] - 1;
					ans[r][c2] = '*';
				}
			}
		}
		for (c = 0; c < 9; c++) {
			memset(cnt, 0, 10);
			for (r = 0; r < 9; r++) {
				k = a[r][c];
				if (!cnt[k]) cnt[k] = r + 1;
				else {
					ans[r][c] = '*';
					r2 = cnt[k] - 1;
					ans[r2][c] = '*';
				}
			}
		}
		for (rr = 0; rr < 9; rr += 3) {
			for (cc = 0; cc < 9; cc += 3) {
				memset(cnt, 0, 10);
				for (r = 0; r < 3; r++) {
					for (c = 0; c < 3; c++) {
						k = a[rr+r][cc+c];
						if (!cnt[k]) cnt[k] = 3*r + c + 1;
						else {
							ans[rr + r][cc + c] = '*';
							r2 = (cnt[k] - 1) / 3, c2 = (cnt[k] - 1) % 3;
							ans[rr + r2][cc + c2] = '*';
						}
					}
				}
			}
		}

		for (r = 0; r < 9; r++) {
			for (c = 0; c < 9; c++) {
				putchar(ans[r][c]), putchar(a[r][c] + '0');
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 524
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

N = inp()
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = inpl()

dp = [[0] * 3 for i in range(N)]
dp[0][0], dp[0][1], dp[0][2] = a[0], b[0], c[0]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i]
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i]
_debug(dp)

mx = 0
for i in dp[N-1]:
    mx = max(mx, i)

print(mx)


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,sum=0;
    cin >> n;
    for(int i=0;;i++){
        if(n/pow(10,i) < 1)break;
        sum += (int)(n/pow(10,i))%10;
        //cout << (int)(n/pow(10,i))%10 << endl;
    }
    cout << ((n%sum == 0)? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static long gcd(long a , long b) {
		if(a > b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		long r = b % a;
		if(r == 0)return a;
		return gcd(a, r);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(), x = sc.nextLong();
		sc.close();
		long ans = 3 * (n - gcd(n, x));
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
std::vector<ll> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,-1); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]==-1) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j){
                if(IsPrime[i*j]==-1)
                    IsPrime[i*j] = i;
            } // (max以下の)iの倍数は
                      // 素数ではない
}

int main() {
    
    ll N;
    cin >>N;
    sieve(N+1);
    vector<ll> di(N+1);
    ll ans=0;
    di[1]=1;
    ans += 1;
    rep3(i,2,N+1){
        ll IP = IsPrime[i];
        if(IP==-1){
            di[i]=2;
        }else{
            ll now = i; 
            ll cnt = 0;
            while(1){
                if(now%IP == 0){
                    now/=IP;
                    cnt++;
                }else{
                    break;
                }
                
            }

            di[i]= di[i/IP]+(di[i/IP])/(cnt);
        }
    //cout<<i<<" "<<di[i]<<" "<<IP<<endl;
        ans +=i*di[i];
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 159500
awk -M '\

function floor(x){
    x+=0
    if(x%1){
        if(x>0)return int(x);
        else   return int(x)-1;
    }else      return x; 
}
function f(x){
    return floor(A*x/B) - A*floor(x/B)
}
{
    A = $1;
    B = $2;
    N = $3;
    if(B-1>N)print f(N)
    else print f(B-1)
}'

Measured memory_bytes: 4628
#include<iostream>
#include<math.h>
#include<fstream>
#include<string.h>
using namespace std;



int solve(int T, int * r) {
	int count = 0;
	for (int i = 1; i <= T; i++) {
		if (i == r[r[i - 1] - 1])
			count++;
	}

	return count / 2;
}

int main() {

	int T;
	int * rabbits;

	cin >> T;

	rabbits = new int[T];
	for (int i = 0; i < T; i++) {
		cin >> rabbits[i];
	}
	cout << solve(T, rabbits) << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 202020;

int n, a[N];
ll pre[N], suf[N];
ll f[N], g[N];
//ll dp[N][N];

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n;
	rep(i, 1, n + 1) cin >> a[i];
//	rep(i, 0, n + 1) rep(j, 1, n + 1) dp[i][j] = -1e18;
//	rep(i, 1, n + 1) rep(j, 1, i + 1) {
//		dp[i][j] = dp[i - 1][j];
//		if(i - 2 >= 0) dp[i][j] = max(dp[i][j], dp[i - 2][j - 1] + a[i]);
//	}
//	de(dp[n][n / 2]);
//	return 0;
	rep(i, 1, n + 1) {
		pre[i] = a[i];
		if(i - 2 > 0) pre[i] += pre[i - 2];
	}
	per(i, 1, n + 1) {
		suf[i] = a[i];
		if(i + 2 <= n) suf[i] += suf[i + 2];
	}
	ll ans = -1e18;
	if(n & 1) {
		ans = max(suf[2], suf[3]);
		ans = max(ans, suf[1] - a[n]);
	//	de(ans);
		rep(i, 2, n - 1) {
			ll res = 0;
			if(i & 1) {
				res = max(pre[i - 1], pre[i - 2]);
				res += suf[i + 2];
			} else {
				res = pre[i - 1];
				res += max(suf[i + 2], suf[i + 3]);
			}
		//	de(res);
			ans = max(ans, res);
		}
		f[2] = -pre[2] + pre[1];
		rep(i, 4, n + 1) if(i % 2 == 0) f[i] = max(-pre[i] + pre[i - 1], f[i - 2]);
		g[n - 1] = -suf[n - 1] + suf[n];
		per(i, 2, n - 1) if(i % 2 == 0) g[i] = max(-suf[i] + suf[i + 1], g[i + 2]);
		rep(i, 2, n + 1) if(i % 2 == 0) ans = max(ans, pre[n - 1] + f[i] + g[i]);
	} else {
		ans = max(pre[n], pre[n - 1]);
		rep(i, 1, n) if(i % 2 == 0) ans = max(ans, pre[i - 1] + suf[i + 2]);
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10648
#include<stdio.h>
#include<assert.h>
#include<math.h>
#include<string.h>
int stack[110];
int top = 0;

void push(int v) { 
	stack[top++] = v; 
}

int  pop() { 
	return stack[--top]; 
}

int getInt(char *s){
	int i, ret = 0;
	int size = strlen(s);

	for (i = 0; i<size; i++){
		ret += (s[i] - '0')*pow(10, size - i - 1);
	}
	return ret;
}

int main(){
	char s[1000];
	int a, b;

	while (scanf("%s", s) != EOF){
		if ('0' <= s[0] && s[0] <= '9'){
			int v = getInt(s);
			push(v);
			continue;
		}
		
		b = pop();
		a = pop();
		if (s[0] == '+'){
			push(a + b);
		}
		else if (s[0] == '-'){
			push(a - b);
		}
		else if (s[0] == '*'){
			push(a*b);
		}
		else{
			assert(0);
		}
	}
	printf("%d\n", pop());
	return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int L;
  cin >> L;

  double ans = 0.0;
  double edge = L / 3.0;
  ans = edge * edge * edge;

  cout << fixed << setprecision(32) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,minj,j,A[100],N,temp,x=0,y;

  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0; i < N; i++){
    minj = i;
    y = 0;
    for(j = i; j < N; j++){
      if(A[j]<A[minj]){
	minj = j;
	y = 1;
      }
    }
    if(y == 1){
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    x++;
    }
  }
    
    for(j = 0; j < N; j++){
    printf("%d",A[j]);
    if(j != N-1) printf(" ");
  }
  printf("\n");

  printf("%d\n",x);

  return 0;
}



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

int calc_y(int y) {
    if(y <= 0) return 0;
    int d3 = y / 3;
    int ret = (20 * 5 + 19 * 5) * y;
    ret += d3 * 5;
    return ret;
}

int calc_m(int m, bool mod3) {
    if(m <= 0) return 0;
    int ret = 0;
    for(int i = 1; i <= m; i++) {
        if(i % 2 == 1 || mod3) ret += 20;
        else ret += 19;
    }
    return ret;
}

int calc(int y, int m, int d) {
    return calc_y(y - 1) +
           calc_m(m - 1, y % 3 == 0) + d;
}

int main() {
    int N;
    cin >> N;
    while(N--) {
        int y, m, d;
        cin >> y >> m >> d;
        cout << calc(1000, 1, 1) - calc(y, m, d) << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
	typedef struct {
		int parent,depth,k;
		int *c;
	} TREE;
void dep(int);

	TREE *t;

int main(){
	int n,i,j,id;
	
	scanf("%d",&n);
	
	t = malloc(sizeof(TREE)*n);
	
	for(i=0;i<n;i++){
		t[i].parent=-1;
		t[i].depth=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d",&id);
		scanf("%d",&t[id].k);
		t[id].c = malloc(sizeof(int) * t[id].k);
		for(j=0;j<t[id].k;j++){
			scanf("%d",&t[id].c[j]);
			t[t[id].c[j]].parent=id;
		}
	}
	for(i=0;i<n;i++){
		if(t[i].parent==-1) dep(i);
	}
	
	for(i=0;i<n;i++){
		if(t[i].parent==-1){
			printf("node %d: parent = %d, depth = %d, root, [",i,t[i].parent,t[i].depth);
			for(j=0;j<t[i].k;j++){
				if(j!=(t[i].k-1)) printf("%d, ",t[i].c[j]);
				else printf("%d",t[i].c[j]);
		}
			printf("]\n");
		}
		else if(t[i].k!=0){
			printf("node %d: parent = %d, depth = %d, internal node, [",i,t[i].parent,t[i].depth);
			for(j=0;j<t[i].k;j++){
				if(j!=(t[i].k-1)) printf("%d, ",t[i].c[j]);
				else printf("%d",t[i].c[j]);
			}
			printf("]\n");
		}
		else {
			printf("node %d: parent = %d, depth = %d, leaf, [",i,t[i].parent,t[i].depth);
			for(j=0;j<t[i].k;j++){
				if(j!=(t[i].k-1)) printf("%d, ",t[i].c[j]);
				else printf("%d",t[i].c[j]);
			}
			printf("]\n");
		}	
	}
		return 0;
}
void dep(int a){
	int j;
	
	if(t[a].k!=0){
		for(j=0;j<t[a].k;j++){
			t[t[a].c[j]].depth = t[a].depth+1;
			dep(t[a].c[j]);
		}
	}
}


Measured memory_bytes: 7588
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int k,s,ans=0;
  cin>>k>>s;
  rep(i,k+1){
    rep(j,k+1){
      int n=i+j;
      if(s-n <=k && 0<=s-n) ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int n, q;
  cin >> n >> q;
  dsu d(n);
  rep(i,q) {
    int t, u, v;
    cin >> t >> u >> v;
    if(t == 0) d.merge(u,v);
    else cout << (d.same(u,v) ? 1 : 0) << endl;
  }
  return 0;
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

vector<int> longpath;
vector<int> path;

const int MAXN = 228;
vector<int> e[MAXN];

const ull INF = numeric_limits<ull>::max();

int mdown[MAXN];

void dfs(int v, int p, int h) {
    int ch = 0;
    for (int u : e[v]) {
        if (u != p) {
            dfs(u, v, h + 1);
            ++ch;
        }
    }

    mdown[h] = max(mdown[h], ch);
}

ull ans = INF;
int ansh = MAXN;

void eval(int mul) {
    ull cans = mul;
    int h = 1;
    while (mdown[h]) {
        cans *= mdown[h++];
    }

    if (h < ansh || h == ansh && cans < ans) {
        ansh = h;
        ans = cans;
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    vector<pair<int, int>> eds;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        eds.emplace_back(a, b);
        e[a].push_back(b);
        e[b].push_back(a);
    }


    for (int v = 1; v <= n; ++v) {
        fill(mdown, mdown + n + 1, 0);
        dfs(v, -1, 1);
        eval(1);
    }

    for (auto ed : eds) {
        fill(mdown, mdown + n + 1, 0);
        dfs(ed.first, ed.second, 1);
        dfs(ed.second, ed.first, 1);
        eval(2);
    }

    cout << ansh << " " << ans << "\n";
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

n = int(input())
neighbors = [[] for i in range(n+1)]
ab = []
for i in range(n-1):
    line = list(map(int, input().split()))
    neighbors[line[0]].append(line[1])
    neighbors[line[1]].append(line[0])
    ab.append((line[0], line[1]))
maximum = 0
neighbors_max = 0
for i in range(n):
    if maximum < len(neighbors[i]):
        neighbors_max = i
        maximum = len(neighbors[i])
edgecolors = {}
reached = {neighbors_max}
def make_other_colors(c, m):
    res = []
    if c > m:
        res += [i+1 for i in range(m)]
    else:
        res += [i+1 for i in range(c-1)]
        res += [maximum-i for i in range(m-c+1)]
    return res
def coloring(v, c):
    if c == 0:
        reached.add(v)
        for i in range(len(neighbors[v])):
            edgecolors[(v, neighbors[v][i])] = i + 1
            edgecolors[(neighbors[v][i], v)] = i + 1
            reached.add(neighbors[v][i])
            coloring(neighbors[v][i], i+1)
        return
    l = len(neighbors[v])
    if l == 1 and neighbors[v][0] in reached:
        reached.add(v)
        return
    other_colors = make_other_colors(c, l-1)
    i = 0
    j = 0
    while i < l:
        if neighbors[v][i] in reached:
            i += 1
            continue
        edgecolors[(v, neighbors[v][i])] = other_colors[j]
        edgecolors[(neighbors[v][i], v)] = other_colors[j]
        reached.add(neighbors[v][i])
        coloring(neighbors[v][i], other_colors[j])
        i += 1
        j += 1
coloring(neighbors_max, 0)
print(maximum)
for i in ab:
    print(edgecolors[i])


Measured memory_bytes: 137244
import itertools
n,m,q=map(int,input().split())
p=[list(map(int,input().split())) for i in range(q)]
ans=0
def init(n):
  c=[i for i in range(1,m+1)]
  cand=[]
  for i in c:
    cand.append([i])
  for _ in range(n-1):
    cand2=[]
    for i in range(len(cand)):
      for j in range(cand[i][-1],m+1):
        cand2.append(cand[i]+[j])
    cand=cand2
  return cand
cand=init(n)
for i in range(len(cand)):
  m=0
  for j in range(q):
    if cand[i][p[j][1]-1]-cand[i][p[j][0]-1]==p[j][2]:
      m+=p[j][3]
  if m>ans:
    ans=m
print(ans)

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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
}

void solveB() {
    int n; cin >> n;
    string s; cin >> s;
    int res = 0;
    for (int i = 0; i + 2 < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
    }
    cout << res;
}

void solveC() {
    int n; cin >> n;
    int p[n], q[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n;i ++) cin >> q[i];
    int arr[n];
    int lim = 1;
    for (int i = 1; i <= n; i++) lim *= i;
    for (int i = 0; i < n; i++) arr[i] = i + 1;
    int a = 0, b = 0;
    for (int i = 0; i < lim; i++) {
        int isA = 1, isB = 1;
        for (int j = 0; j < n; j++) {
            if (arr[j] != q[j]) isB = 0;
            if (arr[j] != p[j]) isA = 0;
        }
        if (isA) a = i;
        if (isB) b = i;
        next_permutation(arr, arr + n);
    }
    cout << abs(a - b);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int find2(long long x) {
    int res = 0;
    while (x % 2 == 0) {
        res++;
        x /= 2;
    }
    return res;
}

void solveD() {
    long long n, m; cin >> n >> m;
    long long arr[n];
    if (n == 1) {
        int x; cin >> x;
        if (x % 2 == 1) cout << 0;
        else {
            x /= 2;
            int res = m / x - m / (2 * x); //(m + x) / (2 * x);
            cout << ((res < 0) ? 0 : res);
        }
        return;
    }
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i] /= 2;
    }
    int two = find2(arr[0]);
    for (int i = 1; i < n; i++) {
        if (find2(arr[i]) != two) {
            cout << 0;
            return;
        }
    }
    long long arrLcm = 1LL;
    for (int i = 0; i < n; i++) arrLcm = lcm(arrLcm, arr[i]);
    long long res = m / arrLcm - m / (2 * arrLcm); //(m + arrLcm) / (2 * arrLcm);
    cout << ((res < 0) ? 0 : res);
}

const long long MOD = 1e9 + 7;

long long modPow(long long b, int p = MOD - 2) {
    if (p == 0) return 1LL;
    long long x = modPow(b, p / 2);
    if (p % 2 == 0) return x * x % MOD;
    return (x * x % MOD) * b % MOD;
}

void solveE() {
    int n; cin >> n;
    long long c[n];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(c, c + n, greater<int>());
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += c[i] * (i + 2) % MOD; //c[i] * (n - i + 1) % MOD;
        res %= MOD;
    }
    res = res * modPow(4LL, n - 1) % MOD;
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    ///solveA();
    ///solveB();
    ///solveC();
    ///solveD();
    solveE();
}


Measured memory_bytes: 1792
n = int(input())
nums = list(map(int, input().split()))

total = 0
smallest = 9999999999999999999999999999999
counter = 0
for i in range(n):
    total += abs(nums[i])
    smallest = min(smallest, abs(nums[i]))
    if nums[i] < 0:
        counter += 1

if counter % 2 == 0:
    print(total)
else:
    print(total - 2*smallest)


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

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

int main() {
  int k;
  cin >> k;
  string s = "ACL";
  rep(_, k - 1) s += "ACL";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define v vector
#define len length()
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll combination(ll n, ll i)
{
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}

int main() {
	// your code goes here
	IOS;
	ll n,m,i;
	ll j,t,x,y,z,k,d;
	cin>>n>>m>>k;
	ll a[n+1],b[m+1],s1[n+1]={0};
	v<ll> s2(m+1,0);
	rep(i,n+1) {
	if(i>0){      
	cin>>a[i];
	s1[i]+=s1[i-1]+a[i];
	}
	//cout<<s1[i]<<" ";
	}
	//cout<<endl;
	rep(i,m+1) {
	
	if(i>0){
	cin>>b[i];
	s2[i]+=s2[i-1]+b[i];
	}
	//cout<<s2[i]<<" ";
	}
	ll maxi=0;
	ll count;
	for(i=0;i<=n;i++){
	      count=0;
	      if(s1[i]>k)
	      break;
	      ll rem=k-s1[i];
	      //cout<<i<<"\n";
	      count+=i;
	      ll ans=ub(s2,rem);
	      if(s2[ans]!=rem)
	      ans--;
	      count+=ans;
	      if(count>maxi)
	      maxi=count;
	}
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 9492